phpstan/phpstan-strict-rules
Opinionated extra rules for PHPStan to enforce strict, strongly typed PHP. Catches loose booleans in conditions, unsafe strict parameters, useless casts, non-numeric arithmetic, variable overwrites in loops, and switch/case type mismatches for safer defensive code.
empty(), requiring === comparisons).empty() bypasses, loose comparisons in authentication logic) by enforcing stricter checks.uselessCast) and enforce numeric operands in arithmetic operations, improving code clarity and potential performance.disallowedLooseComparison) without breaking builds.Adopt if:
empty() or backtick usage).foreach overwrites, dynamic method calls).Look elsewhere if:
empty(), backticks, or dynamic variables) that would require massive refactoring to comply."This package supercharges our PHP code quality by enforcing strict typing and defensive programming—reducing runtime bugs, improving security, and aligning with industry best practices. For example, it catches loose comparisons (==) that could lead to security flaws or arithmetic errors with non-numeric operands. By integrating with our existing PHPStan workflow, we can fail builds on violations and gradually modernize our codebase without disrupting releases. The cost? Minimal—just a Composer install and incremental adoption. The payoff? Fewer production incidents and more maintainable code."
*"We’re adding phpstan/phpstan-strict-rules to enforce stricter PHP standards, like:
==) to prevent type-related bugs.empty() (which silently converts types) in favor of explicit checks.$$foo) and implicit array creation to improve readability.This won’t break existing code overnight—we’ll enable rules incrementally via PHPStan config. It’s a small change with big long-term benefits: fewer bugs, safer refactoring, and code that’s easier to maintain. Let’s start with a pilot in [Module X] and measure the impact on static analysis findings."*
*"We’re adopting phpstan-strict-rules to catch subtle bugs early. Here’s what changes:
empty($var): Use !isset($var) or null !== $var instead.== with === everywhere.(int) $alreadyInt as redundant.foreach will trigger warnings.How to adapt:
composer require --dev phpstan/phpstan-strict-rules.phpstan.neon to include the rules (start with allRules: false and enable rules gradually).This is a net positive: fewer surprises in production and code that’s easier to reason about. Start with the rules that matter most to you!"*
How can I help you explore Laravel packages today?