Find the best Rector rule to solve your problem


Configurable

BooleanInBooleanNotRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInBooleanNotRule"

 class SomeClass
 {
     public function run(string|null $name)
     {
-        if (! $name) {
+        if ($name === null) {
             return 'no name';
         }

         return 'name';
     }
 }
SETS:  Strict Booleans

Configurable

DisallowedEmptyRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\DisallowedConstructs\DisallowedEmptyRule"

 final class SomeEmptyArray
 {
     public function run(array $items)
     {
-        return empty($items);
+        return $items === [];
     }
 }

Configurable

BooleanInTernaryOperatorRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInTernaryOperatorRule"

 final class ArrayCompare
 {
     public function run(array $data)
     {
-        return $data ? 1 : 2;
+        return $data !== [] ? 1 : 2;
     }
 }
SETS:  Strict Booleans

Configurable

DisallowedShortTernaryRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\DisallowedConstructs\DisallowedShortTernaryRule"

 final class ShortTernaryArray
 {
     public function run(array $array)
     {
-        return $array ?: 2;
+        return $array !== [] ? $array : 2;
     }
 }
SETS:  Strict Booleans

Configurable

BooleanInIfConditionRuleFixerRector

Fixer for PHPStan reports by strict type rule - "PHPStan\Rules\BooleansInConditions\BooleanInIfConditionRule"

 final class NegatedString
 {
     public function run(string $name)
     {
-        if ($name) {
+        if ($name !== '') {
             return 'name';
         }

         return 'no name';
     }
 }
SETS:  Strict Booleans