Find the best Rector rule to solve your problem


ExplicitPublicClassMethodRector

Add explicit public method visibility.

 class SomeClass
 {
-    function foo()
+    public function foo()
     {
     }
 }
SETS:  Coding Style

Configurable

FuncCallToConstFetchRector

Changes use of function calls to use constants

 class SomeClass
 {
     public function run()
     {
-        $value = php_sapi_name();
+        $value = PHP_SAPI;
     }
 }
SETS:  Coding Style

ConsistentImplodeRector

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);
     }
 }

CallUserFuncToMethodCallRector

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);
     }
 }

StrictArraySearchRector

Makes array_search search for identical elements

-array_search($value, $items);
+array_search($value, $items, true);
SETS:  Coding Style

CallUserFuncArrayToVariadicRector

Replace call_user_func_array() with variadic

 class SomeClass
 {
     public function run()
     {
-        call_user_func_array('some_function', $items);
+        some_function(...$items);
     }
 }
SETS:  Coding Style

CountArrayToEmptyArrayComparisonRector

Change count array comparison to empty array comparison to improve performance

-count($array) === 0;
-count($array) > 0;
-! count($array);
+$array === [];
+$array !== [];
+$array === [];

VersionCompareFuncCallToConstantRector

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;
     }
 }
SETS:  Coding Style

CatchExceptionNameMatchingTypeRector

Type and name of catch exception should match

 try {
     // ...
-} catch (SomeException $typoException) {
-    $typoException->getMessage();
+} catch (SomeException $someException) {
+    $someException->getMessage();
 }
SETS:  Coding Style

SplitGroupedPropertiesRector

Separate grouped properties to own lines

 class SomeClass
 {
     /**
      * @var string
      */
-    public $isIt, $isIsThough;
+    public $isIt;
+
+    /**
+     * @var string
+     */
+    public $isIsThough;
 }
SETS:  Coding Style

SplitDoubleAssignRector

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;
     }
 }
SETS:  Coding Style

NewlineAfterStatementRector

Add new line after statements to tidify code

 class SomeClass
 {
     public function first()
     {
     }
+
     public function second()
     {
     }
 }
SETS:  Coding Style

RemoveUselessAliasInUseStatementRector

Remove useless alias in use statement as same name with last use statement name

-use App\Bar as Bar;
+use App\Bar;
SETS:  Coding Style

WrapEncapsedVariableInCurlyBracesRector

Wrap encapsed variables in curly braces

 function run($world)
 {
-    echo "Hello $world!";
+    echo "Hello {$world}!";
 }
SETS:  Coding Style

Configurable

EncapsedStringsToSprintfRector

Convert enscaped {$string} to more readable sprintf or concat, if no mask is used

-echo "Unsupported format {$format} - use another";
+echo sprintf('Unsupported format %s - use another', $format);

-echo "Try {$allowed}";
+echo 'Try ' . $allowed;
SETS:  Coding Style

UseClassKeywordForClassNameResolutionRector

Use class keyword for class name resolution in string instead of hardcoded string reference

-$value = 'App\SomeClass::someMethod()';
+$value = \App\SomeClass::class . '::someMethod()';
SETS:  Coding Style

SymplifyQuoteEscapeRector

Prefer quote that are not inside the string

 class SomeClass
 {
     public function run()
     {
-         $name = "\" Tom";
-         $name = '\' Sara';
+         $name = '" Tom';
+         $name = "' Sara";
     }
 }
SETS:  Coding Style

TernaryConditionVariableAssignmentRector

Assign outcome of ternary condition to variable, where applicable

 function ternary($value)
 {
-    $value ? $a = 1 : $a = 0;
+    $a = $value ? 1 : 0;
 }
SETS:  Coding Style

SplitGroupedClassConstantsRector

Separate class constant to own lines

 class SomeClass
 {
-    const HI = true, HELLO = 'true';
+    const HI = true;
+    const HELLO = 'true';
 }
SETS:  Coding Style

RemoveFinalFromConstRector

Remove final from constants in classes defined as final

 final class SomeClass
 {
-    final public const NAME = 'value';
+    public const NAME = 'value';
 }
SETS:  Coding Style

NullableCompareToNullRector

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) {
 }
SETS:  Coding Style

MakeInheritedMethodVisibilitySameAsParentRector

Make method visibility same as parent one

 class ChildClass extends ParentClass
 {
-    public function run()
+    protected function run()
     {
     }
 }

 class ParentClass
 {
     protected function run()
     {
     }
 }
SETS:  Coding Style

NewlineBeforeNewAssignSetRector

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);
     }
 }
SETS:  Coding Style

FuncGetArgsToVariadicParamRector

Refactor func_get_args() in to a variadic param

-function run()
+function run(...$args)
 {
-    $args = \func_get_args();
 }

SeparateMultiUseImportsRector

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;
 }
SETS:  Coding Style

Configurable

StringClassNameToClassConstantRector

Replace string class names by ::class constant

 class AnotherClass
 {
 }

 class SomeClass
 {
     public function run()
     {
-        return 'AnotherClass';
+        return \AnotherClass::class;
     }
 }