voku/phpstan-rules
Additional PHPStan rules to catch risky and redundant condition logic and comparisons. Detects double negatives, PHP 8 behavior changes (0 vs ''), insane/invalid comparisons (0=='0foo', 0==='0'), and type-mismatch checks (e.g., object vs non-object).
composer require --dev voku/phpstan-rules.phpstan/extension-installer, rules will be loaded automatically.includes: - vendor/voku/phpstan-rules/rules.neon to your phpstan.neon file.(string)$foo != ''), which are often missed even at higher levels. It’s especially valuable for teams avoiding PHP 8 BC breaks or enforcing strict value-object usage.!= '', != 0, !== false)0 == '0foo' under PHP 8)false && true, 0 === '0')phpstan.neon:
parameters:
voku:
classesNotInIfConditions: [App\Domain\ValueObject\AbstractValueObject]
checkForAssignments: true
checkYodaConditions: true
This enables stricter validation for value objects and enforces preferred coding style (e.g., no assignments in conditionals).DisallowedCallMethodOnNullRule can be included individually for partial adoption (e.g., before upgrading full PHPStan level).0 vs '': PHP 8 changed behavior for loose comparisons (0 == '' → false, 0 == '0' → true). The rule warns on both, but verify context — some legacy apps rely on pre-PHP 8 semantics.checkYodaConditions: true may conflict with team conventions. Disable if your team uses Yoda style intentionally (e.g.,防错 if (null === $foo)).checkForAssignments: true blocks if ($a = $b) but not if (($a = $b) !== null). Use parentheses explicitly if intentional assignment is needed — otherwise, PHPStan will warn.classesNotInIfConditions reduces noise for VO usage, but ensure subclasses inherit correctly — if EmailVO extends AbstractValueObject, only if ($email->isValid()) is safe.--debug with PHPStan to see which helper (IfConditionHelper) flagged an error. Check 3v4l links in docs to verify PHP version behavior.composer show -i voku/phpstan-rules before upgrades.How can I help you explore Laravel packages today?