Find the best Rector rule to solve your problem
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';
}
}
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 === [];
}
}
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;
}
}
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;
}
}
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';
}
}