Find the best Rector rule to solve your problem. Searching through 647 rules.

Found 19 rules:

ExceptionHandlerTypehintRector

Change typehint from Exception to Throwable.

-function handler(Exception $exception) { ... }
+function handler(Throwable $exception) { ... }
 set_exception_handler('handler');
SETS:  PHP 7.0

ThisCallOnStaticMethodToStaticCallRector

Changes $this->call() to static method to static call

 class SomeClass
 {
     public static function run()
     {
-        $this->eat();
+        static::eat();
     }

     public static function eat()
     {
     }
 }
SETS:  PHP 7.0

EregToPregMatchRector

Changes ereg*() to preg*() calls

-ereg("hi")
+preg_match("#hi#");
SETS:  PHP 7.0

CallUserMethodRector

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");
SETS:  PHP 7.0

RenameMktimeWithoutArgsToTimeRector

Renames mktime() without arguments to time()

 class SomeClass
 {
     public function run()
     {
         $time = mktime(1, 2, 3);
-        $nextTime = mktime();
+        $nextTime = time();
     }
 }
SETS:  PHP 7.0

MultiDirnameRector

Changes multiple dirname() calls to one with nesting level

-dirname(dirname($path));
+dirname($path, 2);
SETS:  PHP 7.0

RandomFunctionRector

Changes rand, srand, and getrandmax to newer alternatives

-rand();
+random_int();
SETS:  PHP 7.0

StaticCallOnNonStaticToInstanceCallRector

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();
     }
 }
SETS:  PHP 7.0

ListSwapArrayOrderRector

list() assigns variables in reverse order - relevant in array assign

-list($a[], $a[]) = [1, 2];
+list($a[], $a[]) = array_reverse([1, 2]);
SETS:  PHP 7.0

ListSplitStringRector

list() cannot split string directly anymore, use str_split()

-list($foo) = "string";
+list($foo) = str_split("string");
SETS:  PHP 7.0

WrapVariableVariableNameInCurlyBracesRector

Ensure variable variables are wrapped in curly braces

 function run($foo)
 {
-    global $$foo->bar;
+    global ${$foo->bar};
 }
SETS:  PHP 7.0

BreakNotInLoopOrSwitchToReturnRector

Convert break outside for/foreach/switch context to return

 class SomeClass
 {
     public function run()
     {
         if ($isphp5)
             return 1;
         else
             return 2;
-        break;
+        return;
     }
 }
SETS:  PHP 7.0

IfIssetToCoalescingRector

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';
     }
 }
SETS:  PHP 7.0

TernaryToSpaceshipRector

Use <=> spaceship instead of ternary with same effect

 function order_func($a, $b) {
-    return ($a < $b) ? -1 : (($a > $b) ? 1 : 0);
+    return $a <=> $b;
 }
SETS:  PHP 7.0

TernaryToNullCoalescingRector

Changes unneeded null check to ?? operator

-$value === null ? 10 : $value;
+$value ?? 10;
SETS:  PHP 7.0

ReduceMultipleDefaultSwitchRector

Remove first default switch, that is ignored

 switch ($expr) {
     default:
-         echo "Hello World";
-
-    default:
          echo "Goodbye Moon!";
          break;
 }
SETS:  PHP 7.0

EmptyListRector

list() cannot be empty

-'list() = $values;'
+'list($unusedGenerated) = $values;'
SETS:  PHP 7.0

IfToSpaceshipRector

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];
 });
SETS:  PHP 7.0

Php4ConstructorRector

Changes PHP 4 style constructor to __construct.

 class SomeClass
 {
-    public function SomeClass()
+    public function __construct()
     {
     }
 }
SETS:  PHP 7.0