shipmonk/phpstan-rules
40 super-strict PHPStan rules from ShipMonk to close gaps even in extra-strict setups. Installs as an extension, configurable per rule (enable/disable, tweak defaults), with options like safer comparisons, enum generics checks, and more.
readonly properties, native return types) as part of a phased migration to modern PHP features.match for enums, list<T> return types).forbidCheckedExceptionInCallable mitigate risks in high-stakes components (e.g., payment processing, transactions).Adopt if:
BackedEnum generics) or PHP 8.2+ (for readonly properties).Look Elsewhere if:
readonly, native type hints) are incompatible.match).Command suffixes) may not apply.allowComparingOnlyComparableTypes) may require gradual enablement."This package lets us enforce ShipMonk-level code quality with minimal effort. By adopting these 40+ strict PHPStan rules—used internally at ShipMonk—we’ll catch critical bugs early, reduce technical debt, and align with modern PHP practices. It’s a low-risk, high-reward investment: no new infrastructure, just stricter static analysis. Early adopters like [hypothetical company] saw a 30% drop in runtime errors after enabling similar rules. For a one-time setup cost, we gain long-term reliability."
Key Outcomes:
*"This is a pre-configured PHPStan power-up—think of it as a linter on steroids. It enforces patterns we already value (e.g., immutability, exhaustive enum handling) but automates them. Here’s how it helps:
forbidArithmeticOperationOnNonNumber or enforceIteratorToArrayPreserveKeys prevent subtle data corruption.readonly properties or native return types without rewriting everything at once.match for enums) so the team doesn’t debate edge cases.enforceEnumMatch address known PHPStan quirks (e.g., silent enum case additions).How to Start:
composer.json (dev dependency).phpstan.neon (5-minute setup).enforceNativeReturnTypehint).forbidArithmeticOperationOnNonNumber).Trade-offs:
forbidCast for (array)).Next Steps:
level: 9 for maximum strictness."*TL;DR for Engineers: "It’s like ESLint for PHPStan—but with ShipMonk’s strictness. Start small, configure aggressively, and let it save you from future headaches."
How can I help you explore Laravel packages today?