This overview is deprecated and replaced by more advanced web search. There you can search and filter by nodes, copy-paste configs for configurable rules and more.
Use https://getrector.com/find-rule instead!
-
Arguments (4)
-
Carbon (4)
-
CodeQuality (69)
-
CodingStyle (29)
-
DeadCode (45)
-
EarlyReturn (8)
-
Instanceof (1)
-
Naming (6)
-
Php52 (2)
-
Php53 (3)
-
Php54 (3)
-
Php55 (6)
-
Php56 (1)
-
Php70 (19)
-
Php71 (7)
-
Php72 (9)
-
Php73 (9)
-
Php74 (14)
-
Php80 (16)
-
Php81 (8)
-
Php82 (5)
-
Php83 (3)
-
Php84 (1)
-
Privatization (4)
-
Removing (5)
-
Renaming (11)
-
Strict (5)
-
Transform (25)
-
TypeDeclaration (57)
-
Visibility (3)
This Rector adds new default arguments in calls of defined methods and class types.
🔧 configure it!
$someObject = new SomeExampleClass;
-$someObject->someMethod();
+$someObject->someMethod(true);
class MyCustomClass extends SomeExampleClass
{
- public function someMethod()
+ public function someMethod($value = true)
{
}
}
Streamline the operator arguments of version_compare function
🔧 configure it!
-version_compare(PHP_VERSION, '5.6', 'gte');
+version_compare(PHP_VERSION, '5.6', 'ge');
Remove parameter of method call
🔧 configure it!
final class SomeClass
{
public function run(Caller $caller)
{
- $caller->process(1, 2);
+ $caller->process(1);
}
}
Replaces defined map of arguments in defined methods and their calls.
🔧 configure it!
$someObject = new SomeClass;
-$someObject->someMethod(SomeClass::OLD_CONSTANT);
+$someObject->someMethod(false);
Convert date()
function call to Carbon::now()->format(*)
class SomeClass
{
public function run()
{
- $date = date('Y-m-d');
+ $date = \Carbon\Carbon::now()->format('Y-m-d');
}
}
Convert new DateTime()
to Carbon::*()
-$date = new \DateTime('today');
+$date = \Carbon\Carbon::today();
Convert new DateTime()
with a method call to Carbon::*()
class SomeClass
{
public function run()
{
- $date = (new \DateTime('today +20 day'))->format('Y-m-d');
+ $date = \Carbon\Carbon::today()->addDays(20)->format('Y-m-d')
}
}
Convert time()
function call to Carbon::now()->timestamp
class SomeClass
{
public function run()
{
- $time = time();
+ $time = \Carbon\Carbon::now()->timestamp;
}
}
include/require to absolute path. This Rector might introduce backwards incompatible code, when the include/require being changed depends on the current working directory.
class SomeClass
{
public function run()
{
- require 'autoload.php';
+ require __DIR__ . '/autoload.php';
require $variable;
}
}
Split 2 assigns ands to separate line
class SomeClass
{
public function run()
{
$tokens = [];
- $token = 4 and $tokens[] = $token;
+ $token = 4;
+ $tokens[] = $token;
}
}
Change array_key_exists()
ternary to coalescing
class SomeClass
{
public function run($values, $keyToMatch)
{
- $result = array_key_exists($keyToMatch, $values) ? $values[$keyToMatch] : null;
+ $result = $values[$keyToMatch] ?? null;
}
}
Change array_merge of non arrays to array directly
class SomeClass
{
public function go()
{
$value = 5;
$value2 = 10;
- return array_merge([$value], [$value2]);
+ return [$value, $value2];
}
}
Negated identical boolean compare to not identical compare (does not apply to non-bool values)
class SomeClass
{
public function run()
{
$a = true;
$b = false;
- var_dump(! $a === $b); // true
- var_dump(! ($a === $b)); // true
+ var_dump($a !== $b); // true
+ var_dump($a !== $b); // true
var_dump($a !== $b); // true
}
}
Refactor call_user_func()
with arrow function to direct call
final class SomeClass
{
public function run()
{
- $result = \call_user_func(fn () => 100);
+ $result = 100;
}
}
Change array_push()
to direct variable assign
$items = [];
-array_push($items, $item);
+$items[] = $item;
Cleanup unneeded nullsafe operator
class HelloWorld {
public function getString(): string
{
return 'hello world';
}
}
function get(): HelloWorld
{
return new HelloWorld();
}
-echo get()?->getString();
+echo get()->getString();
Merges nested if statements
class SomeClass
{
public function run()
{
- if ($cond1) {
- if ($cond2) {
- return 'foo';
- }
+ if ($cond1 && $cond2) {
+ return 'foo';
}
}
}
Simplify $value
= $value
+ 5; assignments to shorter ones
-$value = $value + 5;
+$value += 5;
Use common != instead of less known <> with same meaning
final class SomeClass
{
public function run($one, $two)
{
- return $one <> $two;
+ return $one != $two;
}
}
Change compact()
call to own array
class SomeClass
{
public function run()
{
$checkout = 'one';
$form = 'two';
- return compact('checkout', 'form');
+ return ['checkout' => $checkout, 'form' => $form];
}
}
Add missing dynamic properties
class SomeClass
{
+ /**
+ * @var int
+ */
+ public $value;
+
public function set()
{
$this->value = 5;
}
}
Complete missing if/else brackets
class SomeClass
{
public function run($value)
{
- if ($value)
+ if ($value) {
return 1;
+ }
}
}
Change multiple null compares to ?? queue
class SomeClass
{
public function run()
{
- if ($this->orderItem !== null) {
- return $this->orderItem;
- }
-
- if ($this->orderItemUnit !== null) {
- return $this->orderItemUnit;
- }
-
- return null;
+ return $this->orderItem ?? $this->orderItemUnit;
}
}
Replaces static::* access to private constants with self::*
final class Foo
{
private const BAR = 'bar';
public function run()
{
- $bar = static::BAR;
+ $bar = self::BAR;
}
}
Make if conditions more explicit
final class SomeController
{
public function run($items)
{
- if (!count($items)) {
+ if (count($items) === 0) {
return 'no items';
}
}
}
Add explicit return null to method/function that returns a value, but missed main return
class SomeClass
{
/**
- * @return string|void
+ * @return string|null
*/
public function run(int $number)
{
if ($number > 50) {
return 'yes';
}
+
+ return null;
}
}
Flip type control from null compare to use exclusive instanceof object
function process(?DateTime $dateTime)
{
- if ($dateTime === null) {
+ if (! $dateTime instanceof DateTime) {
return;
}
}
Change count()
in for function to own variable
class SomeClass
{
public function run($items)
{
- for ($i = 5; $i <= count($items); $i++) {
+ $itemsCount = count($items);
+ for ($i = 5; $i <= $itemsCount; $i++) {
echo $items[$i];
}
}
}
Change foreach()
items assign to empty array to direct assign
class SomeClass
{
public function run($items)
{
$collectedItems = [];
- foreach ($items as $item) {
- $collectedItems[] = $item;
- }
+ $collectedItems = $items;
}
}
Simplify foreach
loops into in_array
when possible
-foreach ($items as $item) {
- if ($item === 'something') {
- return true;
- }
-}
-
-return false;
+return in_array('something', $items, true);
Inline just in time array dim fetch assigns to direct return
function getPerson()
{
- $person = [];
- $person['name'] = 'Timmy';
- $person['surname'] = 'Back';
-
- return $person;
+ return [
+ 'name' => 'Timmy',
+ 'surname' => 'Back',
+ ];
}
Move property default from constructor to property default
final class SomeClass
{
- private $name;
+ private $name = 'John';
public function __construct()
{
- $this->name = 'John';
}
}
Change inline if to explicit if
class SomeClass
{
public function run()
{
$userId = null;
- is_null($userId) && $userId = 5;
+ if (is_null($userId)) {
+ $userId = 5;
+ }
}
}
Change is_a()
with object and class name check to instanceof
class SomeClass
{
public function run(object $object)
{
- return is_a($object, SomeType::class);
+ return $object instanceof SomeType;
}
}
Complete missing 3rd argument in case is_a()
function in case of strings
class SomeClass
{
public function __construct(string $value)
{
- return is_a($value, 'stdClass');
+ return is_a($value, 'stdClass', true);
}
}
Change isset on property object to property_exists()
and not null check
class SomeClass
{
private $x;
public function run(): void
{
- isset($this->x);
+ property_exists($this, 'x') && $this->x !== null;
}
}
Joins concat of 2 strings, unless the length is too long
class SomeClass
{
public function run()
{
- $name = 'Hi' . ' Tom';
+ $name = 'Hi Tom';
}
}
Change static method and local-only calls to non-static
class SomeClass
{
public function run()
{
- self::someStatic();
+ $this->someStatic();
}
- private static function someStatic()
+ private function someStatic()
{
}
}
Change OR, AND to ||, && with more common understanding
-if ($f = false or true) {
+if (($f = false) || true) {
return $f;
}
Change unsafe new static()
to new self()
final class SomeClass
{
public function build()
{
- return new static();
+ return new self();
}
}
Ternary number compare to max()
call
class SomeClass
{
public function run($value)
{
- return $value > 100 ? $value : 100;
+ return max($value, 100);
}
}
Move required parameters after optional ones
class SomeObject
{
- public function run($optional = 1, $required)
+ public function run($required, $optional = 1)
{
}
}
Remove sprintf()
wrapper if not needed
class SomeClass
{
public function run()
{
$welcome = 'hello';
- $value = sprintf('%s', $welcome);
+ $value = $welcome;
}
}
Remove useless is_object()
check on combine with instanceof check
-is_object($obj) && $obj instanceof DateTime
+$obj instanceof DateTime
Replace the Double not operator (!!) by type-casting to boolean
-$bool = !!$var;
+$bool = (bool) $var;
Changes settype()
to (type) where possible
class SomeClass
{
public function run($foo)
{
- settype($foo, 'string');
+ $foo = (string) $foo;
- return settype($foo, 'integer');
+ return (int) $foo;
}
}
Shortens else/if to elseif
class SomeClass
{
public function run()
{
if ($cond1) {
return $action1;
- } else {
- if ($cond2) {
- return $action2;
- }
+ } elseif ($cond2) {
+ return $action2;
}
}
}
Simplify array_search to in_array
-array_search("searching", $array) !== false;
+in_array("searching", $array);
-array_search("searching", $array, true) !== false;
+in_array("searching", $array, true);
Simplify bool value compare to true or false
class SomeClass
{
public function run(bool $value, string $items)
{
- $match = in_array($value, $items, TRUE) === TRUE;
+ $match = in_array($value, $items, TRUE);
- $match = in_array($value, $items, TRUE) !== FALSE;
+ $match = in_array($value, $items, TRUE);
}
}
Simplify conditions
-if (! ($foo !== 'bar')) {...
+if ($foo === 'bar') {...
Simplify negated conditions with de Morgan theorem
$a = 5;
$b = 10;
-$result = !($a > 20 || $b <= 50);
+$result = $a <= 20 && $b > 50;
Simplify is_array
and empty
functions combination into a simple identical check for an empty array
-is_array($values) && empty($values)
+$values === []
Simplify empty()
functions calls on empty arrays
$array = [];
-if (empty($values)) {
+if ([] === $values) {
}
Changes foreach that returns set value to ??
-foreach ($this->oldToNewFunctions as $oldFunction => $newFunction) {
- if ($currentFunction === $oldFunction) {
- return $newFunction;
- }
-}
-
-return null;
+return $this->oldToNewFunctions[$currentFunction] ?? null;
Simplify count of func_get_args()
to func_num_args()
-count(func_get_args());
+func_num_args();
Changes if/else for same value as assign to ternary
class SomeClass
{
public function run()
{
- if (empty($value)) {
- $this->arrayBuilt[][$key] = true;
- } else {
- $this->arrayBuilt[][$key] = $value;
- }
+ $this->arrayBuilt[][$key] = empty($value) ? true : $value;
}
}
Changes redundant null check to instant return
$newNode = 'something';
-if ($newNode !== null) {
- return $newNode;
-}
-
-return null;
+return $newNode;
Direct return on if nullable check before return
class SomeClass
{
public function run()
{
- $value = $this->get();
- if (! $value instanceof \stdClass) {
- return null;
- }
-
- return $value;
+ return $this->get();
}
public function get(): ?stdClass {
}
}
Shortens if return false/true to direct return
-if (strpos($docToken->getContent(), "\n") === false) {
- return true;
-}
-
-return false;
+return strpos($docToken->getContent(), "\n") === false;
Removes unneeded array_values()
in in_array()
call
-in_array("key", array_values($array), true);
+in_array("key", $array, true);
Simplify regex pattern to known ranges
class SomeClass
{
public function run($value)
{
- preg_match('#[a-zA-Z0-9+]#', $value);
+ preg_match('#[\w\d+]#', $value);
}
}
Simplify strpos(strtolower()
, "...") calls
-strpos(strtolower($var), "...")
+stripos($var, "...")
Simplify tautology ternary to value
-$value = ($fullyQualifiedTypeHint !== $typeHint) ? $fullyQualifiedTypeHint : $typeHint;
+$value = $fullyQualifiedTypeHint;
Removes useless variable assigns
🔧 configure it!
function () {
- $a = true;
- return $a;
+ return true;
};
function () {
$a = 'Hello, ';
- $a .= 'World!';
- return $a;
+ return $a . 'World!';
};
Changes in_array()
with single element to ===
class SomeClass
{
public function run()
{
- if (in_array(strtolower($type), ['$this'], true)) {
+ if (strtolower($type) === '$this') {
return strtolower($type);
}
}
}
Change switch with only 1 check to if
class SomeObject
{
public function run($value)
{
$result = 1;
- switch ($value) {
- case 100:
+ if ($value === 100) {
$result = 1000;
}
return $result;
}
}
Change static::methodCall()
to self::methodCall()
on final class
final class SomeClass
{
public function d()
{
- echo static::run();
+ echo self::run();
}
private static function run()
{
echo 'test';
}
}
Changes strlen comparison to 0 to direct empty string compare
class SomeClass
{
public function run(string $value)
{
- $empty = strlen($value) === 0;
+ $empty = $value === '';
}
}
Switch negated ternary condition rector
class SomeClass
{
public function run(bool $upper, string $name)
{
- return ! $upper
- ? $name
- : strtoupper($name);
+ return $upper
+ ? strtoupper($name)
+ : $name;
}
}
Change switch (true) to if statements
class SomeClass
{
public function run()
{
- switch (true) {
- case $value === 0:
- return 'no';
- case $value === 1:
- return 'yes';
- case $value === 2:
- return 'maybe';
- };
+ if ($value === 0) {
+ return 'no';
+ }
+
+ if ($value === 1) {
+ return 'yes';
+ }
+
+ if ($value === 2) {
+ return 'maybe';
+ }
}
}
Change ternary empty on array property with array dim fetch to coalesce operator
final class SomeClass
{
private array $items = [];
public function run()
{
- return ! empty($this->items) ? $this->items[0] : 'default';
+ return $this->items[0] ?? 'default';
}
}
Change ternary with false to if and explicit call
final class SomeClass
{
public function run($value, $someMethod)
{
- $value ? $someMethod->call($value) : false;
+ if ($value) {
+ $someMethod->call($value);
+ }
}
}
When throwing into a catch block, checks that the previous exception is passed to the new throw clause
class SomeClass
{
public function run()
{
try {
$someCode = 1;
} catch (Throwable $throwable) {
- throw new AnotherException('ups');
+ throw new AnotherException('ups', $throwable->getCode(), $throwable);
}
}
}
Remove unnecessary ternary expressions
-$foo === $bar ? true : false;
+$foo === $bar;
Change foreach with unused $value
but only $key,
to array_keys()
class SomeClass
{
public function run()
{
$items = [];
- foreach ($values as $key => $value) {
+ foreach (array_keys($values) as $key) {
$items[$key] = null;
}
}
}
unwrap sprintf()
with one argument
-echo sprintf('value');
+echo 'value';
Use ===/!== over ==/!=, it values have the same type
class SomeClass
{
public function run(int $firstValue, int $secondValue)
{
- $isSame = $firstValue == $secondValue;
- $isDiffernt = $firstValue != $secondValue;
+ $isSame = $firstValue === $secondValue;
+ $isDiffernt = $firstValue !== $secondValue;
}
}
Change array_merge()
to spread operator
class SomeClass
{
public function run($iter1, $iter2)
{
- $values = array_merge(iterator_to_array($iter1), iterator_to_array($iter2));
+ $values = [...$iter1, ...$iter2];
// Or to generalize to all iterables
- $anotherValues = array_merge(
- is_array($iter1) ? $iter1 : iterator_to_array($iter1),
- is_array($iter2) ? $iter2 : iterator_to_array($iter2)
- );
+ $anotherValues = [...$iter1, ...$iter2];
}
}
Replace call_user_func_array()
with variadic
class SomeClass
{
public function run()
{
- call_user_func_array('some_function', $items);
+ some_function(...$items);
}
}
Refactor call_user_func()
on known class method to a method call
final class SomeClass
{
public function run()
{
- $result = \call_user_func([$this->property, 'method'], $args);
+ $result = $this->property->method($args);
}
}
Type and name of catch exception should match
try {
// ...
-} catch (SomeException $typoException) {
- $typoException->getMessage();
+} catch (SomeException $someException) {
+ $someException->getMessage();
}
Changes various implode forms to consistent one
class SomeClass
{
public function run(array $items)
{
- $itemsAsStrings = implode($items);
- $itemsAsStrings = implode($items, '|');
+ $itemsAsStrings = implode('', $items);
+ $itemsAsStrings = implode('|', $items);
}
}
Change count array comparison to empty array comparison to improve performance
-count($array) === 0;
-count($array) > 0;
-! count($array);
+$array === [];
+$array !== [];
+$array === [];
Convert enscaped {$string} to more readable sprintf or concat, if no mask is used
🔧 configure it!
-echo "Unsupported format {$format} - use another";
+echo sprintf('Unsupported format %s - use another', $format);
-echo "Try {$allowed}";
+echo 'Try ' . $allowed;
-echo "Unsupported format {$format} - use another";
+echo sprintf('Unsupported format %s - use another', $format);
-echo "Try {$allowed}";
+echo sprintf('Try %s', $allowed);
Refactor func_get_args()
in to a variadic param
-function run()
+function run(...$args)
{
- $args = \func_get_args();
}
Upgrade string callback functions to first class callable
final class SomeClass
{
public function run(array $data)
{
- return array_map('trim', $data);
+ return array_map(trim(...), $data);
}
}
Make method visibility same as parent one
class ChildClass extends ParentClass
{
- public function run()
+ protected function run()
{
}
}
class ParentClass
{
protected function run()
{
}
}
Change multidimensional array access in foreach to array destruct
class SomeClass
{
/**
* @param array<int, array{id: int, name: string}> $users
*/
public function run(array $users)
{
- foreach ($users as $user) {
- echo $user['id'];
- echo sprintf('Name: %s', $user['name']);
+ foreach ($users as ['id' => $id, 'name' => $name]) {
+ echo $id;
+ echo sprintf('Name: %s', $name);
}
}
}
Add new line after statements to tidify code
class SomeClass
{
public function first()
{
}
+
public function second()
{
}
}
Add extra space before new assign set
final class SomeClass
{
public function run()
{
$value = new Value;
$value->setValue(5);
+
$value2 = new Value;
$value2->setValue(1);
}
}
Changes negate of empty comparison of nullable value to explicit === or !== compare
/** @var stdClass|null $value */
-if ($value) {
+if ($value !== null) {
}
-if (!$value) {
+if ($value === null) {
}
Use ++$value or --$value instead of $value++
or $value--
class SomeClass
{
public function run($value = 1)
{
- $value++; echo $value;
- $value--; echo $value;
+ ++$value; echo $value;
+ --$value; echo $value;
}
}
Remove final from constants in classes defined as final
final class SomeClass
{
- final public const NAME = 'value';
+ public const NAME = 'value';
}
Remove useless alias in use statement as same name with last use statement name
-use App\Bar as Bar;
+use App\Bar;
Split multi use imports and trait statements to standalone lines
-use A, B;
+use A;
+use B;
class SomeClass
{
- use SomeTrait, AnotherTrait;
+ use SomeTrait;
+ use AnotherTrait;
}
Split multiple inline assigns to each own lines default value, to prevent undefined array issues
class SomeClass
{
public function run()
{
- $one = $two = 1;
+ $one = 1;
+ $two = 1;
}
}
Separate class constant to own lines
class SomeClass
{
- const HI = true, HELLO = 'true';
+ const HI = true;
+ const HELLO = 'true';
}
Separate grouped properties to own lines
class SomeClass
{
/**
* @var string
*/
- public $isIt, $isIsThough;
+ public $isIt;
+
+ /**
+ * @var string
+ */
+ public $isIsThough;
}
Changes ArrowFunction to be static when possible
-fn (): string => 'test';
+static fn (): string => 'test';
Changes Closure to be static when possible
-function () {
+static function () {
if (rand(0, 1)) {
return 1;
}
return 2;
}
Makes array_search search for identical elements
-array_search($value, $items);
+array_search($value, $items, true);
Prefer quote that are not inside the string
class SomeClass
{
public function run()
{
- $name = "\" Tom";
- $name = '\' Sara';
+ $name = '" Tom';
+ $name = "' Sara";
}
}
Assign outcome of ternary condition to variable, where applicable
function ternary($value)
{
- $value ? $a = 1 : $a = 0;
+ $a = $value ? 1 : 0;
}
Use class
keyword for class name resolution in string instead of hardcoded string reference
-$value = 'App\SomeClass::someMethod()';
+$value = \App\SomeClass::class . '::someMethod()';
Changes use of call to version compare function to use of PHP version constant
class SomeClass
{
public function run()
{
- version_compare(PHP_VERSION, '5.3.0', '<');
+ PHP_VERSION_ID < 50300;
}
}
Wrap encapsed variables in curly braces
function run($world)
{
- echo "Hello $world!";
+ echo "Hello {$world}!";
}
Removes recasting of the same type
$string = '';
-$string = (string) $string;
+$string = $string;
$array = [];
-$array = (array) $array;
+$array = $array;
Reduce always false in a if ( || ) condition
class SomeClass
{
public function run(int $number)
{
- if (! is_int($number) || $number > 50) {
+ if ($number > 50) {
return 'yes';
}
return 'no';
}
}
Remove if condition that is always true
final class SomeClass
{
public function go()
{
- if (1 === 1) {
- return 'yes';
- }
+ return 'yes';
return 'no';
}
}
Remove and true that has no added value
class SomeClass
{
public function run()
{
- return true && 5 === 1;
+ return 5 === 1;
}
}
Remove annotation by names
🔧 configure it!
-/**
- * @method getName()
- */
final class SomeClass
{
}
Remove (string) casting when it comes to concat, that does this by default
class SomeConcatingClass
{
public function run($value)
{
- return 'hi ' . (string) $value;
+ return 'hi ' . $value;
}
}
Remove dead condition above return
final class SomeClass
{
public function go()
{
- if (1 === 1) {
- return 'yes';
- }
-
return 'yes';
}
}
Remove useless continue at the end of loops
while ($i < 10) {
++$i;
- continue;
}
Remove if, foreach and for that does not do anything
class SomeClass
{
public function run($value)
{
- if ($value) {
- }
-
- foreach ($values as $value) {
- }
-
return $value;
}
}
Remove dead instanceof check on type hinted variable
function run(stdClass $stdClass)
{
- if (! $stdClass instanceof stdClass) {
- return false;
- }
-
return true;
}
Remove loop with no body
class SomeClass
{
public function run($values)
{
- for ($i=1; $i<count($values); ++$i) {
- }
}
}
Remove last return in the functions, since does not do anything
class SomeClass
{
public function run()
{
$shallWeDoThis = true;
if ($shallWeDoThis) {
return;
}
-
- return;
}
}
Removes dead code statements
-$value = 5;
-$value;
+$value = 5;
Remove dead try/catch
class SomeClass
{
public function run()
{
- try {
- // some code
- }
- catch (Throwable $throwable) {
- throw $throwable;
- }
}
}
Remove operation with 1 and 0, that have no effect on the value
class SomeClass
{
public function run()
{
- $value = 5 * 1;
- $value = 5 + 0;
+ $value = 5;
+ $value = 5;
}
}
Simplify useless double assigns
-$value = 1;
$value = 1;
Remove duplicated key in defined arrays.
$item = [
- 1 => 'A',
1 => 'B'
];
2 following switch keys with identical will be reduced to one result
class SomeClass
{
public function run()
{
switch ($name) {
case 'clearHeader':
return $this->modifyHeader($node, 'remove');
case 'clearAllHeaders':
- return $this->modifyHeader($node, 'replace');
case 'clearRawHeaders':
return $this->modifyHeader($node, 'replace');
case '...':
return 5;
}
}
}
Remove empty class methods not required by parents
class OrphanClass
{
- public function __construct()
- {
- }
}
Removes non-existing @var
annotations above the code
class SomeClass
{
public function get()
{
- /** @var Training[] $trainings */
return $this->getData();
}
}
Remove initialization with null value from property declarations
class SunshineCommand extends ParentClassWithNewConstructor
{
- private $myVar = null;
+ private $myVar;
}
Remove @var/@param/@return
null docblock
class SomeClass
{
- /**
- * @return null
- */
public function foo()
{
return null;
}
}
Remove unused parent call with no parent class
class OrphanClass
{
public function __construct()
{
- parent::__construct();
}
}
Remove unneeded PHP_VERSION_ID conditional checks
class SomeClass
{
public function run()
{
- if (PHP_VERSION_ID < 80000) {
- return;
- }
-
echo 'do something';
}
}
Remove dead instanceof check on type hinted property
final class SomeClass
{
private $someObject;
public function __construct(SomeObject $someObject)
{
$this->someObject = $someObject;
}
public function run()
{
- if ($this->someObject instanceof SomeObject) {
- return true;
- }
-
- return false;
+ return true;
}
}
Remove unreachable statements
class SomeClass
{
public function run()
{
return 5;
-
- $removeMe = 10;
}
}
Remove unused parameter in constructor
final class SomeClass
{
private $hey;
- public function __construct($hey, $man)
+ public function __construct($hey)
{
$this->hey = $hey;
}
}
Remove unused key in foreach
$items = [];
-foreach ($items as $key => $value) {
+foreach ($items as $value) {
$result = $value;
}
Remove unused if check to non-empty array before foreach of the array
class SomeClass
{
public function run()
{
$values = [];
- if ($values !== []) {
- foreach ($values as $value) {
- echo $value;
- }
+ foreach ($values as $value) {
+ echo $value;
}
}
}
Remove unused class constants
class SomeClass
{
- private const SOME_CONST = 'dead';
-
public function run()
{
}
}
Remove unused parameter, if not required by interface or parent class
class SomeClass
{
- private function run($value, $value2)
+ private function run($value)
{
$this->value = $value;
}
}
Remove unused private method
final class SomeController
{
public function run()
{
return 5;
}
-
- private function skip()
- {
- return 10;
- }
}
Remove unused private properties
class SomeClass
{
- private $property;
}
Remove unused promoted property
class SomeClass
{
public function __construct(
- private $someUnusedDependency,
private $usedDependency
) {
}
public function getUsedDependency()
{
return $this->usedDependency;
}
}
Remove unused parameter in public method on final class without extends and interface
final class SomeClass
{
- public function run($a, $b)
+ public function run($a)
{
echo $a;
}
}
Remove unused assigns to variables
class SomeClass
{
public function run()
{
- $value = 5;
}
}
Remove @param
docblock with same type as parameter type
class SomeClass
{
/**
- * @param string $a
* @param string $b description
*/
public function foo(string $a, string $b)
{
}
}
Remove useless @readonly
annotation on native readonly type
final class SomeClass
{
- /**
- * @readonly
- */
private readonly string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
Remove useless return Expr in __construct()
class SomeClass
{
public function __construct()
{
if (rand(0, 1)) {
$this->init();
- return true;
+ return;
}
if (rand(2, 3)) {
- return parent::construct();
+ parent::construct();
+ return;
}
$this->execute();
}
}
Remove @return
docblock with same type as defined in PHP
use stdClass;
class SomeClass
{
- /**
- * @return stdClass
- */
public function foo(): stdClass
{
}
}
Remove unused @var
annotation for properties
final class SomeClass
{
- /**
- * @var string
- */
public string $name = 'name';
}
Remove if/else if they have same content
class SomeClass
{
public function run()
{
- if (true) {
- return 1;
- } else {
- return 1;
- }
+ return 1;
}
}
Removes unneeded $value
= $value
assigns
function run() {
- $result = $result;
}
Change ternary of bool : false to && bool
class SomeClass
{
public function go()
{
- return $value ? $this->getBool() : false;
+ return $value && $this->getBool();
}
private function getBool(): bool
{
return (bool) 5;
}
}
Remove php version checks if they are passed
// current PHP: 7.2
-if (version_compare(PHP_VERSION, '7.2', '<')) {
- return 'is PHP 7.1-';
-} else {
- return 'is PHP 7.2+';
-}
+return 'is PHP 7.2+';
Change if/else value to early return
class SomeClass
{
public function run()
{
if ($this->hasDocBlock($tokens, $index)) {
- $docToken = $tokens[$this->getDocBlockIndex($tokens, $index)];
- } else {
- $docToken = null;
+ return $tokens[$this->getDocBlockIndex($tokens, $index)];
}
-
- return $docToken;
+ return null;
}
}
Change nested ifs to foreach with continue
class SomeClass
{
public function run()
{
$items = [];
foreach ($values as $value) {
- if ($value === 5) {
- if ($value2 === 10) {
- $items[] = 'maybe';
- }
+ if ($value !== 5) {
+ continue;
}
+ if ($value2 !== 10) {
+ continue;
+ }
+
+ $items[] = 'maybe';
}
}
}
Change nested ifs to early return
class SomeClass
{
public function run()
{
- if ($value === 5) {
- if ($value2 === 10) {
- return 'yes';
- }
+ if ($value !== 5) {
+ return 'no';
+ }
+
+ if ($value2 === 10) {
+ return 'yes';
}
return 'no';
}
}
Changes if || to early return
class SomeClass
{
public function canDrive(Car $newCar)
{
foreach ($cars as $car) {
- if ($car->hasWheels() || $car->hasFuel()) {
+ if ($car->hasWheels()) {
+ continue;
+ }
+ if ($car->hasFuel()) {
continue;
}
$car->setWheel($newCar->wheel);
$car->setFuel($newCar->fuel);
}
}
}
Return early prepared value in ifs
class SomeClass
{
public function run()
{
- $var = null;
-
if (rand(0, 1)) {
- $var = 1;
+ return 1;
}
if (rand(0, 1)) {
- $var = 2;
+ return 2;
}
- return $var;
+ return null;
}
}
Split if statement, when if condition always break execution flow
class SomeClass
{
public function run($value)
{
if ($value) {
throw new \InvalidStateException;
- } else {
- return 10;
}
+
+ return 10;
}
}
Changes Single return of || to early returns
class SomeClass
{
public function accept()
{
- return $this->something() || $this->somethingElse();
+ if ($this->something()) {
+ return true;
+ }
+ return (bool) $this->somethingElse();
}
}
Replace if conditioned variable override with direct return
final class SomeClass
{
public function run($value)
{
if ($value === 50) {
- $value = 100;
+ return 100;
}
return $value;
}
}
Flip negated ternary of instanceof to direct use of object
-echo ! $object instanceof Product ? null : $object->getPrice();
+echo $object instanceof Product ? $object->getPrice() : null;
Renames value variable name in foreach loop to match expression variable
class SomeClass
{
public function run()
{
$array = [];
- foreach ($variables as $property) {
- $array[] = $property;
+ foreach ($variables as $variable) {
+ $array[] = $variable;
}
}
}
Renames value variable name in foreach loop to match method type
class SomeClass
{
public function run()
{
$array = [];
- foreach ($object->getMethods() as $property) {
- $array[] = $property;
+ foreach ($object->getMethods() as $method) {
+ $array[] = $method;
}
}
}
Rename param to match ClassType
final class SomeClass
{
- public function run(Apple $pie)
+ public function run(Apple $apple)
{
- $food = $pie;
+ $food = $apple;
}
}
Rename property and method param to match its type
class SomeClass
{
/**
* @var EntityManager
*/
- private $eventManager;
+ private $entityManager;
- public function __construct(EntityManager $eventManager)
+ public function __construct(EntityManager $entityManager)
{
- $this->eventManager = $eventManager;
+ $this->entityManager = $entityManager;
}
}
Rename variable to match method return type
class SomeClass
{
public function run()
{
- $a = $this->getRunner();
+ $runner = $this->getRunner();
}
public function getRunner(): Runner
{
return new Runner();
}
}
Rename variable to match new ClassType
final class SomeClass
{
public function run()
{
- $search = new DreamSearch();
- $search->advance();
+ $dreamSearch = new DreamSearch();
+ $dreamSearch->advance();
}
}
Use break instead of continue in switch statements
function some_run($value)
{
switch ($value) {
case 1:
echo 'Hi';
- continue;
+ break;
case 2:
echo 'Hello';
break;
}
}
Change property modifier from var
to public
final class SomeController
{
- var $name = 'Tom';
+ public $name = 'Tom';
}
Convert dirname(FILE) to DIR
class SomeClass
{
public function run()
{
- return dirname(__FILE__);
+ return __DIR__;
}
}
Rename old $HTTP_*
variable names to new replacements
-$serverVars = $HTTP_SERVER_VARS;
+$serverVars = $_SERVER;
Use ?: instead of ?, where useful
function elvis()
{
- $value = $a ? $a : false;
+ $value = $a ?: false;
}
Long array to short array
class SomeClass
{
public function run()
{
- return array();
+ return [];
}
}
Remove & from function and method calls
final class SomeClass
{
public function run($one)
{
- return strlen(&$one);
+ return strlen($one);
}
}
Remove 0 from break and continue
class SomeClass
{
public function run($random)
{
- continue 0;
- break 0;
+ continue;
+ break;
$five = 5;
- continue $five;
+ continue 5;
- break $random;
+ break;
}
}
Change __CLASS__
to self::class
class SomeClass
{
public function callOnMe()
{
- var_dump(__CLASS__);
+ var_dump(self::class);
}
}
Change get_called_class()
to self::class on final class
final class SomeClass
{
public function callOnMe()
{
- var_dump(get_called_class());
+ var_dump(self::class);
}
}
Change get_called_class()
to static::class on non-final class
class SomeClass
{
public function callOnMe()
{
- var_dump(get_called_class());
+ var_dump(static::class);
}
}
The /e modifier is no longer supported, use preg_replace_callback instead
class SomeClass
{
public function run()
{
- $comment = preg_replace('~\b(\w)(\w+)~e', '"$1".strtolower("$2")', $comment);
+ $comment = preg_replace_callback('~\b(\w)(\w+)~', function ($matches) {
+ return($matches[1].strtolower($matches[2]));
+ }, $comment);
}
}
Change static::class
to self::class
on final class
final class SomeClass
{
public function callOnMe()
{
- var_dump(static::class);
+ var_dump(self::class);
}
}
Replace string class names by ::class constant
🔧 configure it!
class AnotherClass
{
}
class SomeClass
{
public function run()
{
- return 'AnotherClass';
+ return \AnotherClass::class;
}
}
Changes pow(val, val2) to ** (exp) parameter
-pow(1, 2);
+1**2;
Convert break outside for/foreach/switch context to return
class SomeClass
{
public function run()
{
if ($isphp5)
return 1;
else
return 2;
- break;
+ return;
}
}
Changes call_user_method()/call_user_method_array()
to call_user_func()/call_user_func_array()
-call_user_method($method, $obj, "arg1", "arg2");
+call_user_func(array(&$obj, "method"), "arg1", "arg2");
list()
cannot be empty
-'list() = $values;'
+'list($unusedGenerated) = $values;'
Changes ereg*() to preg*() calls
-ereg("hi")
+preg_match("#hi#");
Change typehint from Exception
to Throwable
.
-function handler(Exception $exception) { ... }
+function handler(Throwable $exception) { ... }
set_exception_handler('handler');
Change if with isset and return to coalesce
class SomeClass
{
private $items = [];
public function resolve($key)
{
- if (isset($this->items[$key])) {
- return $this->items[$key];
- }
-
- return 'fallback value';
+ return $this->items[$key] ?? 'fallback value';
}
}
Changes if/else to spaceship <=> where useful
usort($languages, function ($first, $second) {
-if ($first[0] === $second[0]) {
- return 0;
-}
-
-return ($first[0] < $second[0]) ? 1 : -1;
+return $second[0] <=> $first[0];
});
list()
cannot split string directly anymore, use str_split()
-list($foo) = "string";
+list($foo) = str_split("string");
list()
assigns variables in reverse order - relevant in array assign
-list($a[], $a[]) = [1, 2];
+list($a[], $a[]) = array_reverse([1, 2]);
Changes multiple dirname()
calls to one with nesting level
-dirname(dirname($path));
+dirname($path, 2);
Changes PHP 4 style constructor to __construct.
class SomeClass
{
- public function SomeClass()
+ public function __construct()
{
}
}
Changes rand, srand, and getrandmax to newer alternatives
-rand();
+random_int();
Remove first default switch, that is ignored
switch ($expr) {
default:
- echo "Hello World";
-
- default:
echo "Goodbye Moon!";
break;
}
Renames mktime()
without arguments to time()
class SomeClass
{
public function run()
{
$time = mktime(1, 2, 3);
- $nextTime = mktime();
+ $nextTime = time();
}
}
Changes static call to instance call, where not useful
class Something
{
public function doWork()
{
}
}
class Another
{
public function run()
{
- return Something::doWork();
+ return (new Something)->doWork();
}
}
Changes unneeded null check to ?? operator
-$value === null ? 10 : $value;
+$value ?? 10;
-isset($value) ? $value : 10;
+$value ?? 10;
Use <=> spaceship instead of ternary with same effect
function order_func($a, $b) {
- return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
+ return $a <=> $b;
}
Changes $this->call()
to static method to static call
class SomeClass
{
public static function run()
{
- $this->eat();
+ static::eat();
}
public static function eat()
{
}
}
Ensure variable variables are wrapped in curly braces
function run($foo)
{
- global $$foo->bar;
+ global ${$foo->bar};
}
String cannot be turned into array by assignment anymore
-$string = '';
+$string = [];
$string[] = 1;
Change binary operation between some number + string to PHP 7.1 compatible version
class SomeClass
{
public function run()
{
- $value = 5 + '';
- $value = 5.0 + 'hi';
+ $value = 5 + 0;
+ $value = 5.0 + 0.0;
}
}
Changes is_array + Traversable check to is_iterable
-is_array($foo) || $foo instanceof Traversable;
+is_iterable($foo);
Change list()
to array destruct
class SomeClass
{
public function run()
{
- list($id1, $name1) = $data;
+ [$id1, $name1] = $data;
- foreach ($data as list($id, $name)) {
+ foreach ($data as [$id, $name]) {
}
}
}
Changes multi catch of same exception to single one | separated.
try {
// Some code...
-} catch (ExceptionType1 $exception) {
- $sameCode;
-} catch (ExceptionType2 $exception) {
+} catch (ExceptionType1 | ExceptionType2 $exception) {
$sameCode;
}
Add explicit public constant visibility.
class SomeClass
{
- const HEY = 'you';
+ public const HEY = 'you';
}
Remove extra parameters
-strlen("asdf", 1);
+strlen("asdf");
Use anonymous functions instead of deprecated create_function()
class ClassWithCreateFunction
{
public function run()
{
- $callable = create_function('$matches', "return '$delimiter' . strtolower(\$matches[1]);");
+ $callable = function($matches) use ($delimiter) {
+ return $delimiter . strtolower($matches[1]);
+ };
}
}
Null is no more allowed in get_class()
final class SomeClass
{
public function getItem()
{
$value = null;
- return get_class($value);
+ return $value !== null ? get_class($value) : self::class;
}
}
each()
function is deprecated, use key()
and current()
instead
-list($key, $callback) = each($callbacks);
+$key = key($callbacks);
+$callback = current($callbacks);
+next($callbacks);
Use $result
argument in parse_str()
function
-parse_str($this->query);
-$data = get_defined_vars();
+parse_str($this->query, $result);
+$data = $result;
Replace each()
assign outside loop
$array = ['b' => 1, 'a' => 2];
-$eachedArray = each($array);
+$eachedArray[1] = current($array);
+$eachedArray['value'] = current($array);
+$eachedArray[0] = key($array);
+$eachedArray['key'] = key($array);
+
+next($array);
Make first argument of define()
string
class SomeClass
{
public function run(int $a)
{
- define(CONSTANT_2, 'value');
+ define('CONSTANT_2', 'value');
define('CONSTANT', 'value');
}
}
String asserts must be passed directly to assert()
function nakedAssert()
{
- assert('true === true');
- assert("true === true");
+ assert(true === true);
+ assert(true === true);
}
Removes (unset) cast
-$different = (unset) $value;
+$different = null;
-$value = (unset) $value;
+unset($value);
each()
function is deprecated, use foreach()
instead.
-while (list($key, $callback) = each($callbacks)) {
+foreach ($callbacks as $key => $callback) {
// ...
}
-while (list($key) = each($callbacks)) {
+foreach (array_keys($callbacks) as $key) {
// ...
}
Make use of array_key_first()
and array_key_last()
-reset($items);
-$firstKey = key($items);
+$firstKey = array_key_first($items);
-end($items);
-$lastKey = key($items);
+$lastKey = array_key_last($items);
Changes is_array + Countable check to is_countable
-is_array($foo) || $foo instanceof Countable;
+is_countable($foo);
Adds JSON_THROW_ON_ERROR to json_encode()
and json_decode()
to throw JsonException on error
-json_encode($content);
-json_decode($json);
+json_encode($content, JSON_THROW_ON_ERROR);
+json_decode($json, null, 512, JSON_THROW_ON_ERROR);
Escape - in some cases
-preg_match("#[\w-()]#", 'some text');
+preg_match("#[\w\-()]#", 'some text');
Changes case insensitive constants to sensitive ones.
define('FOO', 42, true);
var_dump(FOO);
-var_dump(foo);
+var_dump(FOO);
Changes case insensitive constants to sensitive ones.
-define('FOO', 42, true);
+define('FOO', 42);
Changes heredoc/nowdoc that contains closing word to safe wrapper name
-$value = <<<A
+$value = <<<A_WRAP
A
-A
+A_WRAP
Convert setcookie argument to PHP7.3 option array
-setcookie('name', $value, 360);
+setcookie('name', $value, ['expires' => 360]);
-setcookie('name', $name, 0, '', '', true, true);
+setcookie('name', $name, ['expires' => 0, 'path' => '', 'domain' => '', 'secure' => true, 'httponly' => true]);
Makes needles explicit strings
$needle = 5;
-$fivePosition = strpos('725', $needle);
+$fivePosition = strpos('725', (string) $needle);
Add "_" as thousands separator in numbers for higher or equals to limitValue config
🔧 configure it!
class SomeClass
{
public function run()
{
- $int = 500000;
- $float = 1000500.001;
+ $int = 500_000;
+ $float = 1_000_500.001;
}
}
Change array_key_exists()
on property to property_exists()
class SomeClass
{
public $value;
}
$someClass = new SomeClass;
-array_key_exists('value', $someClass);
+property_exists($someClass, 'value');
Change closure to arrow function
class SomeClass
{
public function run($meetups)
{
- return array_filter($meetups, function (Meetup $meetup) {
- return is_object($meetup);
- });
+ return array_filter($meetups, fn(Meetup $meetup) => is_object($meetup));
}
}
Change curly based array and string to square bracket
$string = 'test';
-echo $string{0};
+echo $string[0];
$array = ['test'];
-echo $array{0};
+echo $array[0];
Change export()
to ReflectionFunction alternatives
-$reflectionFunction = ReflectionFunction::export('foo');
-$reflectionFunctionAsString = ReflectionFunction::export('foo', true);
+$reflectionFunction = new ReflectionFunction('foo');
+$reflectionFunctionAsString = (string) new ReflectionFunction('foo');
Change filter_var()
with slash escaping to addslashes()
$var= "Satya's here!";
-filter_var($var, FILTER_SANITIZE_MAGIC_QUOTES);
+addslashes($var);
Change hebrevc($str) to nl2br(hebrev($str))
-hebrevc($str);
+nl2br(hebrev($str));
Change mb_strrpos()
encoding argument position
-mb_strrpos($text, "abc", "UTF-8");
+mb_strrpos($text, "abc", 0, "UTF-8");
Change money_format()
to equivalent number_format()
-$value = money_format('%i', $value);
+$value = number_format(round($value, 2, PHP_ROUND_HALF_ODD), 2, '.', '');
Use null coalescing operator ??=
$array = [];
-$array['user_id'] = $array['user_id'] ?? 'value';
+$array['user_id'] ??= 'value';
Add parentheses to nested ternary
-$value = $a ? $b : $a ?: null;
+$value = ($a ? $b : $a) ?: null;
Change deprecated (real) to (float)
class SomeClass
{
public function run()
{
- $number = (real) 5;
+ $number = (float) 5;
$number = (float) 5;
$number = (double) 5;
}
}
Add null default to properties with PHP 7.4 property nullable type
class SomeClass
{
- public ?string $name;
+ public ?string $name = null;
}
Change restore_include_path()
to ini_restore("include_path")
-restore_include_path();
+ini_restore('include_path');
Add missing parameter based on parent class method
class A
{
public function execute($foo)
{
}
}
class B extends A{
- public function execute()
+ public function execute($foo)
{
}
}
Change annotation to attribute
🔧 configure it!
use Symfony\Component\Routing\Annotation\Route;
class SymfonyRoute
{
- /**
- * @Route("/path", name="action") api route
- */
+ #[Route(path: '/path', name: 'action')] // api route
public function action()
{
}
}
Change switch()
to match()
-switch ($input) {
- case Lexer::T_SELECT:
- $statement = 'select';
- break;
- case Lexer::T_UPDATE:
- $statement = 'update';
- break;
- default:
- $statement = 'error';
-}
+$statement = match ($input) {
+ Lexer::T_SELECT => 'select',
+ Lexer::T_UPDATE => 'update',
+ default => 'error',
+};
Change get_class($object) to faster $object::class
class SomeClass
{
public function run($object)
{
- return get_class($object);
+ return $object::class;
}
}
Change $this::class
to static::class or self::class depends on class modifier
class SomeClass
{
public function run()
{
- return $this::class;
+ return static::class;
}
}
Change simple property init and assign to constructor promotion
🔧 configure it!
class SomeClass
{
- public float $price;
-
public function __construct(
- float $price = 0.0
+ public float $price = 0.0
) {
- $this->price = $price;
}
}
Changes method visibility from final private to only private
class SomeClass
{
- final private function getter() {
+ private function getter() {
return $this;
}
}
Change ternary type resolve to get_debug_type()
class SomeClass
{
public function run($value)
{
- return is_object($value) ? get_class($value) : gettype($value);
+ return get_debug_type($value);
}
}
Change mixed docs type to mixed typed
class SomeClass
{
- /**
- * @param mixed $param
- */
- public function run($param)
+ public function run(mixed $param)
{
}
}
Changed nested annotations to attributes
🔧 configure it!
use Doctrine\ORM\Mapping as ORM;
class SomeEntity
{
- /**
- * @ORM\JoinTable(name="join_table_name",
- * joinColumns={@ORM\JoinColumn(name="origin_id")},
- * inverseJoinColumns={@ORM\JoinColumn(name="target_id")}
- * )
- */
+ #[ORM\JoinTable(name: 'join_table_name')]
+ #[ORM\JoinColumn(name: 'origin_id')]
+ #[ORM\InverseJoinColumn(name: 'target_id')]
private $collection;
}
Remove unused variable in catch()
final class SomeClass
{
public function run()
{
try {
- } catch (Throwable $notUsedThrowable) {
+ } catch (Throwable) {
}
}
}
Adds static visibility to __set_state()
methods
class SomeClass
{
- public function __set_state($properties) {
+ public static function __set_state($properties) {
}
}
Replace strpos()
!== false and strstr()
with str_contains()
class SomeClass
{
public function run()
{
- return strpos('abc', 'a') !== false;
+ return str_contains('abc', 'a');
}
}
Change helper functions to str_ends_with()
class SomeClass
{
public function run()
{
- $isMatch = substr($haystack, -strlen($needle)) === $needle;
+ $isMatch = str_ends_with($haystack, $needle);
- $isNotMatch = substr($haystack, -strlen($needle)) !== $needle;
+ $isNotMatch = !str_ends_with($haystack, $needle);
}
}
class SomeClass
{
public function run()
{
- $isMatch = substr($haystack, -9) === 'hardcoded;
+ $isMatch = str_ends_with($haystack, 'hardcoded');
- $isNotMatch = substr($haystack, -9) !== 'hardcoded';
+ $isNotMatch = !str_ends_with($haystack, 'hardcoded');
}
}
Change helper functions to str_starts_with()
class SomeClass
{
public function run()
{
- $isMatch = substr($haystack, 0, strlen($needle)) === $needle;
+ $isMatch = str_starts_with($haystack, $needle);
- $isNotMatch = substr($haystack, 0, strlen($needle)) !== $needle;
+ $isNotMatch = ! str_starts_with($haystack, $needle);
}
}
Add Stringable
interface to classes with __toString()
method
-class SomeClass
+class SomeClass implements Stringable
{
- public function __toString()
+ public function __toString(): string
{
return 'I can stringz';
}
}
Upgrade array callable to first class callable
final class SomeClass
{
public function run()
{
- $name = [$this, 'name'];
+ $name = $this->name(...);
}
public function name()
{
}
}
Refactor MyCLabs enum class to native Enum
-use MyCLabs\Enum\Enum;
-
-final class Action extends Enum
+enum Action : string
{
- private const VIEW = 'view';
- private const EDIT = 'edit';
+ case VIEW = 'view';
+ case EDIT = 'edit';
}
Refactor MyCLabs enum fetch to Enum const
-$name = SomeEnum::VALUE()->getKey();
+$name = SomeEnum::VALUE;
Replace property declaration of new state with direct new
class SomeClass
{
- private Logger $logger;
-
public function __construct(
- ?Logger $logger = null,
+ private Logger $logger = new NullLogger,
) {
- $this->logger = $logger ?? new NullLogger;
}
}
Change null to strict string defined function call args
class SomeClass
{
public function run()
{
- preg_split("#a#", null);
+ preg_split("#a#", '');
}
}
Decorate read-only property with readonly
attribute
class SomeClass
{
public function __construct(
- private string $name
+ private readonly string $name
) {
}
public function getName()
{
return $this->name;
}
}
Refactor Spatie enum class to native Enum
🔧 configure it!
-use \Spatie\Enum\Enum;
-
-/**
- * @method static self draft()
- * @method static self published()
- * @method static self archived()
- */
-class StatusEnum extends Enum
+enum StatusEnum : string
{
+ case DRAFT = 'draft';
+ case PUBLISHED = 'published';
+ case ARCHIVED = 'archived';
}
Refactor Spatie enum method calls
-$value1 = SomeEnum::SOME_CONSTANT()->getValue();
-$value2 = SomeEnum::SOME_CONSTANT()->value;
-$name1 = SomeEnum::SOME_CONSTANT()->getName();
-$name2 = SomeEnum::SOME_CONSTANT()->name;
+$value1 = SomeEnum::SOME_CONSTANT->value;
+$value2 = SomeEnum::SOME_CONSTANT->value;
+$name1 = SomeEnum::SOME_CONSTANT->name;
+$name2 = SomeEnum::SOME_CONSTANT->name;
Add SensitiveParameter attribute to method and function configured parameters
🔧 configure it!
class SomeClass
{
- public function run(string $password)
+ public function run(#[\SensitiveParameter] string $password)
{
}
}
Prior PHP 8.2 FilesystemIterator::SKIP_DOTS was always set and could not be removed, therefore FilesystemIterator::SKIP_DOTS is added in order to keep this behaviour.
-new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME);
+new FilesystemIterator(__DIR__, FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::SKIP_DOTS);
Decorate read-only class with readonly
attribute
-final class SomeClass
+final readonly class SomeClass
{
public function __construct(
- private readonly string $name
+ private string $name
) {
}
}
Change deprecated utf8_decode and utf8_encode to mb_convert_encoding
-utf8_decode($value);
-utf8_encode($value);
+mb_convert_encoding($value, 'ISO-8859-1');
+mb_convert_encoding($value, 'UTF-8', 'ISO-8859-1');
Replace deprecated "${var}" to "{$var}"
$c = "football";
-echo "I like playing ${c}";
+echo "I like playing {$c}";
Add override attribute to overridden methods
class ParentClass
{
public function foo()
{
}
}
class ChildClass extends ParentClass
{
+ #[\Override]
public function foo()
{
}
}
Add type to constants based on their value
final class SomeClass
{
- public const TYPE = 'some_type';
+ public const string TYPE = 'some_type';
}
Combine separated host and port on ldap_connect()
args
-ldap_connect('ldap://ldap.example.com', 389);
+ldap_connect('ldap://ldap.example.com:389');
Make implicit nullable param to explicit
-function foo(string $param = null) {}
+function foo(?string $param = null) {}
PHPUnit test case will be finalized
use PHPUnit\Framework\TestCase;
-class SomeClass extends TestCase
+final class SomeClass extends TestCase
{
}
Change protected class method to private if possible
final class SomeClass
{
- protected function someMethod()
+ private function someMethod()
{
}
}
Change property to private if possible
final class SomeClass
{
- protected $value;
+ private $value;
}
Privatize getter of local property to property
class SomeClass
{
private $some;
public function run()
{
- return $this->getSome() + 5;
+ return $this->some + 5;
}
private function getSome()
{
return $this->some;
}
}
Removes defined arguments in defined methods and their calls.
🔧 configure it!
$someObject = new SomeClass;
-$someObject->someMethod(true);
+$someObject->someMethod();
Remove argument by position by function name
🔧 configure it!
-remove_last_arg(1, 2);
+remove_last_arg(1);
Remove function
🔧 configure it!
-$x = 'something';
-var_dump($x);
+$x = 'something';
Removes interfaces usage from class.
🔧 configure it!
-class SomeClass implements SomeInterface
+class SomeClass
{
}
Remove specific traits from code
🔧 configure it!
class SomeClass
{
- use SomeTrait;
}
Turns defined annotations above properties and methods to their new values.
🔧 configure it!
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
/**
- * @test
+ * @scenario
*/
public function someMethod()
{
}
}
Rename attribute class names
🔧 configure it!
-#[SimpleRoute()]
+#[BasicRoute()]
class SomeClass
{
}
Replaces defined class constants in their calls.
🔧 configure it!
-$value = SomeClass::OLD_CONSTANT;
-$value = SomeClass::OTHER_OLD_CONSTANT;
+$value = SomeClass::NEW_CONSTANT;
+$value = DifferentClass::NEW_CONSTANT;
Replaces defined classes by new ones.
🔧 configure it!
namespace App;
-use SomeOldClass;
+use SomeNewClass;
-function someFunction(SomeOldClass $someOldClass): SomeOldClass
+function someFunction(SomeNewClass $someOldClass): SomeNewClass
{
- if ($someOldClass instanceof SomeOldClass) {
- return new SomeOldClass;
+ if ($someOldClass instanceof SomeNewClass) {
+ return new SomeNewClass;
}
}
Replace constant by new ones
🔧 configure it!
final class SomeClass
{
public function run()
{
- return MYSQL_ASSOC;
+ return MYSQLI_ASSOC;
}
}
Rename param within closures and arrow functions based on use with specified method calls
🔧 configure it!
-(new SomeClass)->process(function ($param) {});
+(new SomeClass)->process(function ($parameter) {});
Turns defined function call new one.
🔧 configure it!
-view("...", []);
+Laravel\Templating\render("...", []);
Turns method names to new ones.
🔧 configure it!
$someObject = new SomeExampleClass;
-$someObject->oldMethod();
+$someObject->newMethod();
Replaces defined old properties by new ones.
🔧 configure it!
-$someObject->someOldProperty;
+$someObject->someNewProperty;
Turns method names to new ones.
🔧 configure it!
-SomeClass::oldStaticMethod();
+AnotherExampleClass::newStaticMethod();
Change string value
🔧 configure it!
class SomeClass
{
public function run()
{
- return 'ROLE_PREVIOUS_ADMIN';
+ return 'IS_IMPERSONATOR';
}
}
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule"
🔧 configure it!
class SomeClass
{
public function run(string|null $name)
{
- if (! $name) {
+ if ($name === null) {
return 'no name';
}
return 'name';
}
}
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule"
🔧 configure it!
final class NegatedString
{
public function run(string $name)
{
- if ($name) {
+ if ($name !== '') {
return 'name';
}
return 'no name';
}
}
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule"
🔧 configure it!
final class ArrayCompare
{
public function run(array $data)
{
- return $data ? 1 : 2;
+ return $data !== [] ? 1 : 2;
}
}
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule"
🔧 configure it!
final class SomeEmptyArray
{
public function run(array $items)
{
- return empty($items);
+ return $items === [];
}
}
Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule"
🔧 configure it!
final class ShortTernaryArray
{
public function run(array $array)
{
- return $array ?: 2;
+ return $array !== [] ? $array : 2;
}
}
Add the AllowDynamicProperties
attribute to all classes
🔧 configure it!
namespace Example\Domain;
+#[AllowDynamicProperties]
class SomeObject {
public string $someProperty = 'hello world';
}
Add interface by used trait
🔧 configure it!
-class SomeClass
+class SomeClass implements SomeInterface
{
use SomeTrait;
}
Change array dim fetch to method call
🔧 configure it!
-$app['someService'];
+$app->make('someService');
Replace key value on specific attribute to class constant
🔧 configure it!
use Doctrine\ORM\Mapping\Column;
+use Doctrine\DBAL\Types\Types;
class SomeClass
{
- #[Column(type: "string")]
+ #[Column(type: Types::STRING)]
public $name;
}
Change const fetch to class const fetch
🔧 configure it!
-$x = CONTEXT_COURSE
+$x = course::LEVEL
Changes use of function calls to use constants
🔧 configure it!
class SomeClass
{
public function run()
{
- $value = php_sapi_name();
+ $value = PHP_SAPI;
}
}
Turns defined function calls to local method calls.
🔧 configure it!
class SomeClass
{
+ /**
+ * @var \Namespaced\SomeRenderer
+ */
+ private $someRenderer;
+
+ public function __construct(\Namespaced\SomeRenderer $someRenderer)
+ {
+ $this->someRenderer = $someRenderer;
+ }
+
public function run()
{
- view('...');
+ $this->someRenderer->view('...');
}
}
Change configured function calls to new Instance
🔧 configure it!
class SomeClass
{
public function run()
{
- $array = collection([]);
+ $array = new \Collection([]);
}
}
Turns defined function call to static method call.
🔧 configure it!
-view("...", []);
+SomeClass::render("...", []);
Merges old interface to a new one, that already has its methods
🔧 configure it!
-class SomeClass implements SomeInterface, SomeOldInterface
+class SomeClass implements SomeInterface
{
}
Change method call to function call
🔧 configure it!
final class SomeClass
{
public function show()
{
- return $this->render('some_template');
+ return view('some_template');
}
}
Turns method call "$this->something()"
to property fetch "$this->something"
🔧 configure it!
class SomeClass
{
public function run()
{
- $this->someMethod();
+ $this->someProperty;
}
}
Change method call to desired static call
🔧 configure it!
final class SomeClass
{
private $anotherDependency;
public function __construct(AnotherDependency $anotherDependency)
{
$this->anotherDependency = $anotherDependency;
}
public function loadConfiguration()
{
- return $this->anotherDependency->process('value');
+ return StaticCaller::anotherMethod('value');
}
}
Change new Object to static call
🔧 configure it!
class SomeClass
{
public function run()
{
- new Cookie($name);
+ Cookie::create($name);
}
}
Replaces parent class to specific traits
🔧 configure it!
-class SomeClass extends Nette\Object
+class SomeClass
{
+ use Nette\SmartObject;
}
Turns property assign of specific type and property name to method call
🔧 configure it!
$someObject = new SomeClass;
-$someObject->oldProperty = false;
+$someObject->newMethodCall(false);
Replaces properties assign calls be defined methods.
🔧 configure it!
-$result = $object->property;
-$object->property = $value;
+$result = $object->getProperty();
+$object->setProperty($value);
-$bare = $object->bareProperty;
+$bare = $object->getConfig('someArg');
Change RectorConfig to RectorConfigBuilder
-return static function (RectorConfig $rectorConfig): void {
- $rectorConfig->rule(SomeRector::class);
-};
+return RectorConfig::configure()->rules([SomeRector::class]);
Changes method calls in child of specific types to defined property method call
🔧 configure it!
final class SomeClass
{
public function run(SomeTypeToReplace $someTypeToReplace)
{
- $someTypeToReplace->someMethodCall();
+ $this->someProperty->someMethodCall();
}
}
Add #[\ReturnTypeWillChange] attribute to configured instanceof class with methods
🔧 configure it!
class SomeClass implements ArrayAccess
{
+ #[\ReturnTypeWillChange]
public function offsetGet($offset)
{
}
}
Turns static call to function call.
🔧 configure it!
-OldClass::oldMethod("args");
+new_function("args");
Change static call to service method via constructor injection
🔧 configure it!
-use Nette\Utils\FileSystem;
+use App\Custom\SmartFileSystem;
class SomeClass
{
+ /**
+ * @var SmartFileSystem
+ */
+ private $smartFileSystem;
+
+ public function __construct(SmartFileSystem $smartFileSystem)
+ {
+ $this->smartFileSystem = $smartFileSystem;
+ }
+
public function run()
{
- return FileSystem::write('file', 'content');
+ return $this->smartFileSystem->dumpFile('file', 'content');
}
}
Change static call to new instance
🔧 configure it!
class SomeClass
{
public function run()
{
- $dotenv = JsonResponse::create(['foo' => 'bar'], Response::HTTP_OK);
+ $dotenv = new JsonResponse(['foo' => 'bar'], Response::HTTP_OK);
}
}
Changes strings to specific constants
🔧 configure it!
final class SomeSubscriber
{
public static function getSubscribedEvents()
{
- return ['compiler.post_dump' => 'compile'];
+ return [\Yet\AnotherClass::CONSTANT => 'compile'];
}
}
Wrap return value of specific method
🔧 configure it!
final class SomeClass
{
public function getItem()
{
- return 1;
+ return [1];
}
}
Add known return type to arrow function
-fn () => [];
+fn (): array => [];
Add "never" return-type for closure that never return anything
-function () {
+function (): never {
throw new InvalidException();
}
Add closure return type void if there is no return
-function () {
+function (): void {
};
Add function return type void if there is no return
-function restore() {
+function restore(): void {
}
Change private method param type to strict type, based on passed strict types
final class SomeClass
{
public function run(int $value)
{
$this->resolve($value);
}
- private function resolve($value)
+ private function resolve(int $value)
{
}
}
Adds param type declaration based on PHPUnit provider return type declaration
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
/**
* @dataProvider provideData()
*/
- public function test($value)
+ public function test(string $value)
{
}
public static function provideData()
{
yield ['name'];
}
}
Add param types where needed
🔧 configure it!
class SomeClass
{
- public function process($name)
+ public function process(string $name)
{
}
}
Add param types where needed
🔧 configure it!
-(new SomeClass)->process(function ($parameter) {});
+(new SomeClass)->process(function (string $parameter) {});
Adds param type declaration based on property type the value is assigned to PHPUnit provider return type declaration
final class SomeClass
{
private string $name;
- public function setName($name)
+ public function setName(string $name)
{
$this->name = $name;
}
}
Add exact fixed array type in known cases
+use PhpCsFixer\Tokenizer\Token;
use PhpCsFixer\Tokenizer\Tokens;
class SomeClass
{
+ /**
+ * @param Tokens<Token>
+ */
public function run(Tokens $tokens)
{
}
}
Add type to property by added rules, mostly public/property by parent type
🔧 configure it!
class SomeClass extends ParentClass
{
- public $name;
+ public string $name;
}
Add missing return type declaration based on parent class method
- class:
Rector\TypeDeclaration\Rector\ClassMethod\AddReturnTypeDeclarationBasedOnParentClassMethodRector
class A
{
public function execute(): int
{
}
}
class B extends A{
- public function execute()
+ public function execute(): int
{
}
}
Add return type declarations from yields
class SomeClass
{
- public function provide()
+ /**
+ * @return Iterator<int>
+ */
+ public function provide(): Iterator
{
yield 1;
}
}
Changes defined return typehint of method and class.
🔧 configure it!
class SomeClass
{
- public function getData()
+ public function getData(): array
{
}
}
Add void to PHPUnit test methods
use PHPUnit\Framework\TestCase;
class SomeClass extends TestCase
{
- public function testSomething()
+ public function testSomething(): void
{
}
}
Add param and return types on resource docblock
🔧 configure it!
class SomeClass
{
- /**
- * @param resource|null $resource
- */
- public function setResource($resource)
+ public function setResource(?App\ValueObject\Resource $resource)
{
}
- /**
- * @return resource|null
- */
- public function getResource()
+ public function getResource(): ?App\ValueObject\Resource
{
}
}
Add return type void to function like without any return
final class SomeClass
{
- public function getValues()
+ public function getValues(): void
{
$value = 1000;
return;
}
}
Change && and || between nullable objects to instanceof compares
function someFunction(?SomeClass $someClass)
{
- if ($someClass && $someClass->someMethod()) {
+ if ($someClass instanceof SomeClass && $someClass->someMethod()) {
return 'yes';
}
return 'no';
}
Add return bool, based on direct true/false returns
class SomeClass
{
- public function resolve($value)
+ public function resolve($value): bool
{
if ($value) {
return false;
}
return true;
}
}
Add bool return type based on strict bool returns type operations
class SomeClass
{
- public function resolve($first, $second)
+ public function resolve($first, $second): bool
{
return $first > $second;
}
}
Add return type to classes that extend Doctrine\ORM\EntityRepository
based on return Doctrine method names
use Doctrine\ORM\EntityRepository;
/**
* @extends EntityRepository<SomeType>
*/
final class SomeRepository extends EntityRepository
{
- public function getActiveItem()
+ public function getActiveItem(): ?SomeType
{
return $this->findOneBy([
'something'
]);
}
}
Add return type to closures based on known return values
-function () {
+function (): int {
return 100;
};
Add declare(strict_types=1) if missing
+declare(strict_types=1);
+
function someFunction()
{
}
Change empty()
on nullable object to instanceof check
class SomeClass
{
public function run(?AnotherObject $anotherObject)
{
- if (empty($anotherObject)) {
+ if (! $anotherObject instanceof AnotherObject) {
return false;
}
return true;
}
}
Add declare strict types to a limited amount of classes at a time, to try out in the wild and increase level gradually
🔧 configure it!
+declare(strict_types=1);
+
function someFunction()
{
}
Set DateTime to DateTimeInterface for DateTime property with DateTimeInterface docblock
final class SomeClass
{
- /**
- * @var DateTimeInterface
- */
- private DateTime $dateTime;
+ private DateTimeInterface $dateTime;
}
Add int/float return type based on strict typed returns
class SomeClass
{
- public function increase($value)
+ public function increase($value): int
{
return ++$value;
}
}
Add int/float return type based on strict scalar returns type
class SomeClass
{
- public function getNumber()
+ public function getNumber(): int
{
return 200;
}
}
Change param type based on passed method call type
class SomeTypedService
{
public function run(string $name)
{
}
}
final class UseDependency
{
public function __construct(
private SomeTypedService $someTypedService
) {
}
- public function go($value)
+ public function go(string $value)
{
$this->someTypedService->run($value);
}
}
Change param type based on parent param type
class SomeControl
{
public function __construct(string $name)
{
}
}
class VideoControl extends SomeControl
{
- public function __construct($name)
+ public function __construct(string $name)
{
parent::__construct($name);
}
}
Add property type based on strict setter and getter method
final class SomeClass
{
- private $name = 'John';
+ private string $name = 'John';
public function setName(string $name): void
{
$this->name = $name;
}
public function getName(): string
{
return $this->name;
}
}
Add "never" return-type for methods that never return anything
final class SomeClass
{
- public function run()
+ public function run(): never
{
throw new InvalidException();
}
}
Add basic ? nullable type to class methods and functions, as of PHP 7.1
final class SomeClass
{
- public function getData()
+ public function getData(): ?int
{
if (rand(0, 1)) {
return null;
}
return 100;
}
}
Add known property and return MockObject types
class SomeTest extends TestCase
{
- public function createSomeMock()
+ public function createSomeMock(): \PHPUnit\Framework\MockObject\MockObject
{
$someMock = $this->createMock(SomeClass::class);
return $someMock;
}
}
Add return type to function like with return cast
final class SomeClass
{
- public function action($param)
+ public function action($param): array
{
try {
return (array) $param;
} catch (Exception $exception) {
// some logging
throw $exception;
}
}
}
Add return type from return direct array
final class AddReturnArray
{
- public function getArray()
+ public function getArray(): array
{
return [1, 2, 3];
}
}
Add return type to function like with return new
final class SomeClass
{
- public function create()
+ public function create(): Project
{
return new Project();
}
}
Add strict type declaration based on returned constants
class SomeClass
{
public const NAME = 'name';
- public function run()
+ public function run(): string
{
return self::NAME;
}
}
Add return type from strict return $this
final class SomeClass
{
- public function run()
+ public function run(): self
{
return $this;
}
}
Add strict return type based native function or native method
final class SomeClass
{
- public function run()
+ public function run(): int
{
return strlen('value');
}
}
Add strict return array type based on created empty array and returned
final class SomeClass
{
- public function run()
+ public function run(): array
{
$values = [];
return $values;
}
}
Add return type based on strict parameter type
class SomeClass
{
- public function resolve(ParamType $item)
+ public function resolve(ParamType $item): ParamType
{
return $item;
}
}
Add method return type based on strict ternary values
final class SomeClass
{
- public function getValue($number)
+ public function getValue($number): int
{
return $number ? 100 : 500;
}
}
Add return type from strict return type of call
final class SomeClass
{
- public function getData()
+ public function getData(): int
{
return $this->getNumber();
}
private function getNumber(): int
{
return 1000;
}
}
Add return method return type based on strict typed property
final class SomeClass
{
private int $age = 100;
- public function getAge()
+ public function getAge(): int
{
return $this->age;
}
}
Add return type from symfony serializer
final class SomeClass
{
private \Symfony\Component\Serializer\Serializer $serializer;
- public function resolveEntity($data)
+ public function resolveEntity($data): SomeType
{
return $this->serializer->deserialize($data, SomeType::class, 'json');
}
}
Add union return type
final class SomeClass
{
- public function getData()
+ public function getData(): null|\DateTime|\stdClass
{
if (rand(0, 1)) {
return null;
}
if (rand(0, 1)) {
return new DateTime('now');
}
return new stdClass;
}
}
Add array type based on array dim fetch use
class SomeClass
{
- public function resolve($item)
+ public function resolve(array $item)
{
return $item['name'];
}
}
Add string type based on concat use
class SomeClass
{
- public function resolve($item)
+ public function resolve(string $item)
{
return $item . ' world';
}
}
Add string return type based on returned string scalar values
final class SomeClass
{
- public function foo($condition)
+ public function foo($condition): string
{
if ($condition) {
return 'yes';
}
return 'no';
}
}
Add string return type based on returned strict string values
final class SomeClass
{
- public function foo($condition, $value)
+ public function foo($condition, $value): string;
{
if ($value) {
return 'yes';
}
return strtoupper($value);
}
}
Add typed property from assigned types
🔧 configure it!
final class SomeClass
{
- private $name;
+ private string|null $name = null;
public function run()
{
$this->name = 'string';
}
}
Add typed property from assigned mock
use PHPUnit\Framework\TestCase;
final class SomeTest extends TestCase
{
- private $someProperty;
+ private \PHPUnit\Framework\MockObject\MockObject $someProperty;
protected function setUp(): void
{
$this->someProperty = $this->createMock(SomeMockedClass::class);
}
}
Add typed property from JMS Serializer Type attribute
final class SomeClass
{
#[\JMS\Serializer\Annotation\Type('string')]
- private $name;
+ private ?string $name = null;
}
Add typed properties based only on strict constructor types
class SomeObject
{
- private $name;
+ private string $name;
public function __construct(string $name)
{
$this->name = $name;
}
}
Add strict typed property based on setUp()
strict typed assigns in TestCase
use PHPUnit\Framework\TestCase;
final class SomeClass extends TestCase
{
- private $value;
+ private int $value;
public function setUp()
{
$this->value = 1000;
}
}
Change while null compare to strict instanceof check
final class SomeClass
{
public function run(?SomeClass $someClass)
{
- while ($someClass !== null) {
+ while ($someClass instanceof SomeClass) {
// do something
}
}
}
Change visibility of constant from parent class.
🔧 configure it!
class FrameworkClass
{
protected const SOME_CONSTANT = 1;
}
class MyClass extends FrameworkClass
{
- public const SOME_CONSTANT = 1;
+ protected const SOME_CONSTANT = 1;
}
Change visibility of method from parent class.
🔧 configure it!
class FrameworkClass
{
protected function someMethod()
{
}
}
class MyClass extends FrameworkClass
{
- public function someMethod()
+ protected function someMethod()
{
}
}
Add explicit public method visibility.
class SomeClass
{
- function foo()
+ public function foo()
{
}
}