Find the best Rector rule to solve your problem
each() function is deprecated, use foreach() instead.
-while (list($key, $callback) = each($callbacks)) {
+foreach ($callbacks as $key => $callback) {
// ...
}
String asserts must be passed directly to assert()
function nakedAssert()
{
- assert('true === true');
- assert("true === true");
+ assert(true === true);
+ assert(true === true);
}
Make first argument of define() string
class SomeClass
{
public function run(int $a)
{
- define(CONSTANT_2, 'value');
+ define('CONSTANT_2', 'value');
define('CONSTANT', 'value');
}
}
Use $result argument in parse_str() function
-parse_str($this->query);
-$data = get_defined_vars();
+parse_str($this->query, $result);
+$data = $result;
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;
}
}
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);
each() function is deprecated, use key() and current() instead
-list($key, $callback) = each($callbacks);
+$key = key($callbacks);
+$callback = current($callbacks);
+next($callbacks);
Removes (unset) cast
-$different = (unset) $value;
+$different = null;
-$value = (unset) $value;
+unset($value);
Turns defined function call new one.
-view("...", []);
+Laravel\Templating\render("...", []);