Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Phpstan Strict Rules

Phpstan Strict Rules Laravel Package

phpstan/phpstan-strict-rules

Extra-strict, opinionated PHPStan rules for highly defensive, strongly typed PHP. Enforces boolean conditions, numeric operands, strict calls (e.g., in_array), detects useless casts, prevents loop variable overwrites, and requires matching switch/case types.

View on GitHub
Deep Wiki
Context7

Extra strict and opinionated rules for PHPStan

Frequently asked questions about Phpstan Strict Rules
How do I install phpstan/phpstan-strict-rules in a Laravel project?
Run `composer require --dev phpstan/phpstan-strict-rules` and add it to your PHPStan config (`rules.neon`) under `[rules]`. For Laravel, ensure PHPStan is already integrated via `phpstan/extension-installer` or manually in `phpstan.neon`.
Which Laravel versions are compatible with this package?
This package works with Laravel 9+ (PHP 8.1+) and Laravel 10 (PHP 8.2+). It’s a static analysis tool, so it doesn’t modify runtime behavior—just enforce stricter coding standards during development.
Can I enable only specific rules instead of all strict rules?
Yes. In your `rules.neon`, disable `allRules: true` and enable individual rules like `booleansInConditions: true` or `strictFunctionCalls: true`. This lets you adopt strictness incrementally.
Will this break my existing Laravel codebase?
It may flag violations in loosely typed code (e.g., `if ($var)` when `$var` isn’t boolean). Start with a baseline run (`phpstan analyse --level=max`) and enable rules gradually to avoid massive refactoring.
How do I suppress false positives, like for legacy array functions?
Use `@suppress` PHPDoc comments or configure suppressions in `phpstan.neon` under `[suppressionFiles]`. For example, suppress `strictFunctionCalls` for `in_array` calls where strict mode isn’t needed.
Does this package slow down Laravel’s CI/CD pipeline?
Minimally. Static analysis adds <1s to builds for 10k LOC. Cache results with `phpstan --generate-baseline` or run in parallel. For large projects, prioritize critical paths first.
How does this compare to PHPStan’s default rules?
This package adds opinionated rules (e.g., `numericOperandsInArithmeticOperators`, `switchConditionsMatchingType`) that PHPStan’s default level (`--level=max`) doesn’t enforce. It’s for teams prioritizing defensive programming.
Can I use this with Laravel’s built-in PHPStan integration?
Yes. Laravel’s `phpstan` facade or `phpstan.neon` config works seamlessly. Just ensure your `composer.json` includes PHPStan as a dev dependency and extend its config with the strict rules.
What’s the best way to test this in a Laravel project?
Start with `phpstan analyse --level=max` to catch existing issues, then enable strict rules incrementally. Use `phpstan --error-format=github` for CI-friendly output and fail builds on violations.
Are there alternatives for stricter PHPStan rules in Laravel?
Other PHPStan extensions like `phpstan/extension-installer` or `phpstan/phpstan-doctrine` focus on framework-specific rules. However, `phpstan-strict-rules` is unique for its opinionated, defensive coding focus (e.g., boolean conditions, type safety).
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codraw/graphviz
nexmo/api-specification
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata