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.
Architecture fit. Unchanged in kind: this is a dev-only static-analysis extension for PHPStan, not a runtime library. It fits teams already running PHPStan as a CI gate and wanting an opinionated policy layer for strictly typed PHP. No application architecture footprint, no production dependency, no Laravel service-provider registration. The architectural question remains cultural: does the codebase tolerate "extremely defensive" rules, or will teams suppress them locally? Release 2.1.0 does not change this positioning.
Integration feasibility. Still low effort to install: composer require --dev phpstan/phpstan-strict-rules, then either phpstan/extension-installer or an explicit includes: vendor/phpstan/phpstan-strict-rules/rules.neon. Rules remain controlled through parameters.strictRules, with individual toggles and an allRules: false mode for incremental adoption. However, the dependency floor has moved materially: 2.1.0 requires PHPStan 2.3.0+. Teams on PHPStan 1.x cannot adopt this release without a major-version PHPStan upgrade, which is the dominant integration cost for this version — far larger than config curation.
Technical risk. Moderate adoption risk, low security risk. The primary risk in 2.1.0 is the hard PHPStan 2.3.0 requirement. This is effectively a breaking change for any team pinned to PHPStan 1.x or to PHPStan 2.0–2.2, and it means Composer will either resolve an older strict-rules release or force a PHPStan upgrade mid-stream. Secondary risk: 2.1.0 contains rule-behavior refinements — arithmetic operand rules now name the node types they target, and loop-variable-overwrite reporting is narrowed to variables still in use. The narrowing is a genuine false-positive reduction (good), but the arithmetic message change can invalidate existing ignoreErrors entries and baseline fingerprints, producing either unexpected CI noise or silently stale ignores. The package remains tightly coupled to PHPStan versions, MIT-licensed, maintained under the PHPStan org, and community-supported with no commercial SLA.
Key questions.
ignoreErrors patterns match arithmetic-operand message text, and will they need regeneration?Stack fit. Strong fit for Laravel/PHP shops on Composer and CI, but conditional on PHPStan 2.x. It composes cleanly with PHPStan and Larastan; the TPM must confirm the chosen Larastan version supports PHPStan 2.3+, since Larastan historically lags PHPStan majors. It remains orthogonal to Pint/PHP-CS-Fixer. Treat it as part of the quality gate, not a formatting tool.
Migration path. Use a phased rollout, now gated on the PHPStan major upgrade:
strictRules.allRules: false; enable one or two high-value rules (e.g., strictFunctionCalls, disallowedLooseComparison).ignoreErrors entries that reference arithmetic-operand messages, which changed in 2.1.0.allRules: true.Compatibility. Pin phpstan/phpstan to ^2.3 and phpstan/phpstan-strict-rules to ^2.1 as a coordinated pair. Verify PHP runtime support in the CI matrix against both. Prefer extension-installer to reduce config drift, documenting the manual rules.neon include as a fallback. Note that 2.1.0's branch activity (2.1.x opened, 2.0.x merged forward) signals continued minor releases; expect further PHPStan-minor coupling and keep upgrade sequencing owned by one person.
Sequencing. Order of operations matters more than in the prior assessment: PHPStan major upgrade → extension compatibility validation → strict-rules install with minimal rule set → baseline → expansion. Pilot on a single bounded service or module for one sprint and measure violation count, remediation effort, and developer sentiment. Avoid big-bang enablement and avoid stacking the PHPStan upgrade and strict-rules adoption in the same change window.
Maintenance. Low but non-zero, and slightly higher than before given the PHPStan 2.3 floor. No production patching burden, but maintenance now includes staying current on PHPStan minors, since strict-rules minors can raise the floor. Assign an internal owner for PHPStan config and version alignment to prevent silent drift.
Support. Community-supported via GitHub issues; no vendor SLA. PHPStan org backing provides credibility but no contractual response times. Internal triage capability for rule behavior remains a prerequisite; do not depend on upstream for urgent fixes, particularly during a PHPStan major transition.
Scaling. Analysis time grows with codebase size, and PHPStan 2.x rule changes plus strict rules can increase CI duration. Use result caching, parallel analysis, and path scoping. For monorepos, prefer per-package configs and incremental adoption over a single global ruleset. Track CI minutes and failure rate as adoption scales, and expect a one-time CI cost spike during the PHPStan 2.3 upgrade.
Failure modes.
ignoreErrors patterns, causing stale ignores or unexpected failures.Ramp-up. Budget one to two sprints for pilot setup, baseline creation, and developer education — plus dedicated effort for the PHPStan 2.x upgrade if not already complete. Organization-wide rollout remains a quarter-scale change when remediation is included. Provide short guidance on why each rule exists, how to fix common violations, and when an exception is legitimate. Appoint a "rules champion" to review exceptions. Measure success by new-violation catch rate, baseline shrinkage, CI stability, and developer feedback — not by rule count alone.
How can I help you explore Laravel packages today?