phpstan/phpstan-strict-rules
Extra strict, opinionated PHPStan rules for defensive, strongly typed PHP: require booleans in conditions, strict function-call flags, numeric arithmetic operands, matching switch types, no useless casts, and safer loop variable handling.
disallowedLooseComparison, strictFunctionCalls, booleansInConditions, arithmeticOperandTypes, etc.) become a debt inventory you can chart sprint over sprint — far more defensible in a roadmap conversation than "the code feels fragile."== vs ===, in_array without strict mode, and empty() are classic sources of production incidents. This package converts those idioms into build failures in exactly those modules first.Adopt when:
Look elsewhere / deprioritize when:
Adoption caveats to validate before committing: confirm the PHPStan version pairing (now ≥ 2.3.0 for this release line — budget the PHPStan upgrade as its own line item if you're behind); note that installing it also changes some PHPStan core defaults (so behavior shifts even with allRules: false); and confirm the rules you actually want — not all of them — map to your domain risk.
What changed in 2.1.0 and why it matters to the plan: the PHPStan floor moved to 2.3.0, and two refinements reduce the "linter noise" objection that most often kills this kind of adoption. Loop-variable-overwrite findings are now reported only for variables still in use, cutting a known false-positive class out of the baseline; arithmetic-operand-rule messages now name the node types involved, which shortens triage and lowers the per-finding fix cost. Net effect: slightly higher entry cost (the PHPStan upgrade), materially better signal-to-noise once you're in — which strengthens the read-only spike case rather than weakening it.
For executives (one paragraph): A free, MIT-licensed, dev-only extension that makes our existing static analysis stricter about the specific PHP idioms that cause production bugs — loose comparisons, missing strict flags on in_array/array_search, empty(), mismatched switch types, and arithmetic on mixed operands. It ships nothing to production and adds no runtime dependency or performance risk; it only turns classes of defects into CI failures before release. It is maintained by the same organization that maintains PHPStan, so abandonment risk is low despite the modest star count. Cost is roughly one Composer line plus a timeboxed cleanup sprint — and, if we're behind, a PHPStan upgrade to 2.3.0 first. Benefit is fewer type-related incidents in our highest-risk code paths and an audit-ready, per-rule count of our technical debt.
For engineering leads: Drop-in via Composer with phpstan/extension-installer, or a one-line rules.neon include. Requires PHPStan ≥ 2.3.0 from the 2.1.x line onward, so sequence the PHPStan upgrade ahead of it. Every rule has a named config toggle and its own error identifier, so we can enable rules one at a time, write baselines per directory, and scope the strict ruleset to the modules that carry real risk first. 2.1.0 also tightens the loop-variable-overwrite rule to only flag variables still in use and makes arithmetic-operand errors state which node types are expected — both reduce baseline noise and review churn. It composes with — doesn't replace — PHPStan levels, Pint, and our test suite.
For the sponsor / decision ask: Approve a timeboxed spike — install in a branch (including the PHPStan 2.3.0 bump if needed), run it read-only against the codebase, and report violation counts per rule and per module. Those numbers turn this from a tooling preference into a scoped, costed cleanup proposal with a defensible priority order. Low downside: if the findings aren't worth the churn, we remove one dev dependency and revert the config.
How can I help you explore Laravel packages today?