Find the best Rector rule to solve your problem. Searching through 645 rules.
Found 10 rules:
Remove unused promoted property
class SomeClass
{
public function __construct(
- private $someUnusedDependency,
private $usedDependency
) {
}
public function getUsedDependency()
{
return $this->usedDependency;
}
}
Remove unused private properties
class SomeClass
{
- private $property;
}
Remove unused assigns to variables
class SomeClass
{
public function run()
{
- $value = 5;
}
}
Remove initialization with null value from property declarations
class SunshineCommand extends ParentClassWithNewConstructor
{
- private $myVar = null;
+ private $myVar;
}
Remove unused class constants
class SomeClass
{
- private const SOME_CONST = 'dead';
-
public function run()
{
}
}
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 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 unused key in foreach
$items = [];
-foreach ($items as $key => $value) {
+foreach ($items as $value) {
$result = $value;
}
Remove useless re-assign from property promotion
class SomeClass
{
public function __construct(private \stdClass $std)
{
- $this->std = $std;
}
}
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;
}
}