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 Rules

Phpstan Rules Laravel Package

shipmonk/phpstan-rules

40 super-strict PHPStan rules from ShipMonk to plug gaps in extra-strict setups. Install via Composer, include rules.neon, then enable/disable or tune rules per-project. Targets tricky PHP edge cases like unsafe comparisons, casts, arrays, enums and more.

View on GitHub
Deep Wiki
Context7

📏 Various extra strict PHPStan rules we found useful in ShipMonk.

Frequently asked questions about Phpstan Rules
How do I install and enable these PHPStan rules in a Laravel project?
Run `composer require --dev shipmonk/phpstan-rules` and add `includes: - vendor/shipmonk/phpstan-rules/rules.neon` to your `phpstan.neon`. The package integrates seamlessly with Laravel’s existing PHPStan setup via Composer and minimal config changes.
Which Laravel version and PHPStan version are supported?
This package works with Laravel 9+ and PHP 8.1+. Some rules (e.g., `enforceReadonlyPublicProperty`) require PHP 8.2+. Check the [README](https://github.com/shipmonk-rnd/phpstan-rules) for PHPStan version compatibility, as rules may depend on PHPStan 1.10.x+ features.
Can I disable specific rules or customize their behavior?
Yes. Use the `parameters.shipmonkRules` section in `phpstan.neon` to enable/disable rules or tweak their behavior. For example, `forbidCast: { enabled: false }` disables unsafe cast checks. Rules are merged by default, so use `!` to override defaults.
Will these rules break existing Laravel code (e.g., Eloquent models or Blade templates)?
Some rules (e.g., `forbidCast` or `forbidCheckedExceptionInCallable`) may flag legitimate Laravel patterns like `(array) $model->toArray()` or dynamic closures in queues. Start with `enabled: false` for critical paths, then enable rules incrementally. Use blacklists to exclude known false positives.
How do I handle legacy Laravel code that doesn’t follow modern PHP practices?
Exclude directories or files from PHPStan analysis using `excludeFiles` or `ignoreErrors` in `phpstan.neon`. For example, `ignoreErrors: ['src/OldLegacyCode.php']` skips specific files. Pair with Laravel’s `phpstan-baseline.php` to baseline legacy code.
Are there performance concerns running these rules in CI?
With 40 rules, PHPStan runs may slow down CI. Mitigate this by parallelizing runs (`--parallel`) or excluding tests (`--exclude-tests`). Monitor memory usage with `--memory-limit=1G` and optimize by disabling rules that aren’t critical for your project.
Do these rules support Laravel-specific patterns like Eloquent or Nova?
No. This package focuses on general PHP strictness (e.g., enums, casts, arrays). For Laravel-specific rules (e.g., Eloquent method safety), you’ll need to extend the package or use alternatives like `nunomaduro/phpstan-laravel`. Start with these rules for core PHP safety, then layer Laravel-specific tools.
How do I test if a rule is working correctly?
Run PHPStan with `--error-format=json` to validate rule output. For example, `phpstan analyse --error-format=json` generates structured data to verify rule triggers. Use `phpstan --help` for debugging flags like `--debug`. Test incrementally by enabling one rule at a time.
Can I use these rules with Laravel Pint or PestPHP?
Yes. These rules integrate independently with Laravel Pint (for formatting) and PestPHP (for testing). Configure PHPStan separately in `phpstan.neon`; Pint and PestPHP won’t interfere. Use them together in CI/CD pipelines for a full static analysis + testing workflow.
What’s the best way to adopt these rules in a team?
Start by enabling rules in `warn-only` mode (e.g., `forbidCast: { enabled: true, reportUnsafe: true }`) to educate developers. Use GitHub/GitLab CI to fail builds only after a grace period. Document exceptions in `phpstan.neon` and track false positives with custom scripts or dashboards.
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/framework-extra-bundle
codraw/messenger
codraw/security
codraw/mailer
codraw/contracts
codraw/profiling
codraw/dependency-injection
codraw/tester
codraw/core
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