Find the best Rector rule to solve your problem. Searching through 1010 rules.
Found 21 rules:
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);
}
}
Makes array_search search for identical elements
-array_search($value, $items);
+array_search($value, $items, true);
Replace call_user_func_array() with variadic
class SomeClass
{
public function run()
{
- call_user_func_array('some_function', $items);
+ some_function(...$items);
}
}
Set in_array strict to true when defined on similar type
class BothStrings
{
public function run(string $value)
{
- return in_array($value, ['one', 'two', 'three']);
+ return in_array($value, ['one', 'two', 'three'], true);
}
}
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;
}
}
Add new line space between class constants, properties and class methods to make it more readable
final class SomeClass
{
public const NAME = 'name';
+
public function first()
{
}
+
public function second()
{
}
}
Type and name of catch exception should match
try {
// ...
-} catch (SomeException $typoException) {
- $typoException->getMessage();
+} catch (SomeException $someException) {
+ $someException->getMessage();
}
Separate grouped properties to own lines
class SomeClass
{
/**
* @var string
*/
- public $isIt, $isIsThough;
+ public $isIt;
+
+ /**
+ * @var string
+ */
+ public $isIsThough;
}
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;
}
}
Add empty new line after different-type statements to improve code readability
class SomeClass
{
public function run($input)
{
$value = 5 * $input;
+
$secondValue = $value ^ 5;
+
return $value - $secondValue;
}
}
Remove useless alias in use statement as same name with last use statement name
-use App\Bar as Bar;
+use App\Bar;
Prefer quote that are not inside the string
class SomeClass
{
public function run()
{
- $name = "\" Tom";
- $name = '\' Sara';
+ $name = '" Tom';
+ $name = "' Sara";
}
}
Use class keyword for class name resolution in string instead of hardcoded string reference
-$value = 'App\SomeClass::someMethod()';
+$value = \App\SomeClass::class . '::someMethod()';
Separate class constant to own lines
class SomeClass
{
- const HI = true, HELLO = 'true';
+ const HI = true;
+ const HELLO = 'true';
}
Change alternative if/elseif/else/endif syntax to bracket syntax
-if ($value) :
+if ($value) {
$result = 1;
-else :
+} else {
$result = 2;
-endif;
+}
Make method visibility same as parent one
class ChildClass extends ParentClass
{
- public function run()
+ protected function run()
{
}
}
class ParentClass
{
protected function run()
{
}
}
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);
+
$foo = new Value;
$foo->bar = 5;
+
$bar = new Value;
$bar->foo = 1;
}
}
Refactor func_get_args() in to a variadic param
-function run()
+function run(...$args)
{
- $args = \func_get_args();
}
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;
}
Replace string class names by constant
class AnotherClass
{
}
class SomeClass
{
public function run()
{
- return 'AnotherClass';
+ return \AnotherClass::class;
}
}
Complete missing if/else brackets
class SomeClass
{
public function run($value)
{
- if ($value)
+ if ($value) {
return 1;
+ }
}
}