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 Laravel Package

sidz/phpstan-rules

Custom PHPStan rules aimed at Laravel projects, helping catch common mistakes and enforce best practices. Adds extra static analysis checks tailored to typical framework patterns, improving code quality, consistency, and confidence during refactors.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install the package via Composer:
    composer require --dev sidz/phpstan-rules
    
  2. Extend your phpstan.neon config by including the ruleset:
    includes:
      - vendor/sidz/phpstan-rules/rules.neon
    
  3. Run PHPStan for immediate effect:
    vendor/bin/phpstan analyse src
    
    Expect actionable messages for style/architecture violations (e.g., forbidden method calls, inconsistent type hints, or non-PSR-12 naming) without needing custom rule implementations.

Implementation Patterns

  • Layer-specific enforcement: Enable/disable rule groups per project layer (e.g., disallow doctrine queries in domain layer) by combining with parameters > phpstan.rules overrides.
  • Gradual adoption: In large codebases, pair with errorMessages to selectively exclude legacy issues while enforcing rules only on new code (via paths + ignore blocks).
  • CI guardrails: Add a dedicated phpstan.ci.neon layer that strictly enables all rules without ignoring errors—ideal for failing builds when standards regress.
  • Team coordination: Share rule configurations across repos by publishing your own phpstan-team-rules.neon that extends sidz/phpstan-rules and adds custom project rules.

Gotchas and Tips

  • Rule naming conflicts: This package extends PHPStan—do not override built-in rules unless explicitly documented. Prefer new rule classes (e.g., Sidz\PHPStan\Rules\NoPublicPropertyRule) to avoid confusion.
  • Cache invalidation: Rules may rely on internal symfony/dependency-injection services—always rm -rf phpstan/cache after upgrading to avoid stale errors.
  • Opt-in strictness: Some rules (e.g., NoDefaultArgumentsRule) may break BC in libraries. Use ignore in phpstan.neon for vendor code or legacy projects.
  • Customization hooks: Rules are defined as services—override them by adding your own services: block in phpstan.neon to tweak severity (errorLevel: 2 → warning, 1 → error).
  • Diagnosis clarity: When debugging, run with --debug to see which rule class triggered an error—this helps triage misfired warnings orfalse positives.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport