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

lookyman/phpstan-symfony

PHPStan extension for Symfony projects. Improves static analysis with Symfony-specific type inference and container/framework awareness, helping catch bugs earlier and reduce false positives when analyzing services, controllers, and common Symfony patterns.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Check Compatibility Since this package is deprecated and last updated in 2018, verify if your project still uses Symfony 3.x/4.x (its target range). If using Symfony 5+ or PHPStan 1.0+, consider alternatives like:

  2. Installation Add to composer.json (if absolutely necessary):

    composer require --dev lookyman/phpstan-symfony
    

    Ensure PHPStan is also installed:

    composer require --dev phpstan/phpstan
    
  3. First Use Case Run PHPStan with Symfony rules:

    vendor/bin/phpstan analyse src --level=max
    

    Check for Symfony-specific errors (e.g., invalid service calls, missing annotations).


Implementation Patterns

Usage Patterns

  1. Symfony-Specific Rule Integration

    • The package extends PHPStan with Symfony-aware checks (e.g., validating ContainerInterface calls, Route annotations).
    • Example: Detects unused ParamConverter services or invalid EventDispatcher listeners.
  2. Configuration Extend phpstan.neon to enable Symfony rules:

    includes:
        - vendor/lookyman/phpstan-symfony/extension.neon
    
  3. Workflow Integration

    • CI/CD: Add to static analysis steps (e.g., GitHub Actions):
      - name: Run PHPStan
        run: vendor/bin/phpstan analyse --level=max
      
    • Pre-Commit Hooks: Use tools like phpstan with husky to catch issues early.
  4. Custom Rules

    • Override default rules by extending the extension’s SymfonyExtension class (if needed).

Integration Tips

  • Symfony Flex Projects: If using Symfony Flex, prioritize the official phpstan/phpstan-symfony for compatibility.
  • Legacy Projects: For Symfony 3.x/4.x, this package might work, but test thoroughly—some rules may break.
  • Combining with Other Extensions: Use alongside phpstan/phpstan-doctrine or phpstan/phpstan-laravel (if applicable).

Gotchas and Tips

Pitfalls

  1. Deprecation Risks

    • The package is archived and unmaintained. New Symfony/PHPStan versions will break it.
    • Symptom: ClassNotFoundException for Symfony 5+ classes (e.g., AutowiringPass).
  2. Rule Inaccuracy

    • Rules may produce false positives/negatives due to outdated Symfony knowledge (e.g., incorrect YamlFileLoader assumptions).
  3. Configuration Conflicts

    • Overlapping rules with other PHPStan extensions (e.g., phpstan/phpstan-symfony) can cause rule duplication or silent failures.
  4. Performance Overhead

    • Older PHPStan versions (pre-0.12) may slow down with this extension due to lack of optimizations.

Debugging Tips

  • Enable Verbose Mode:

    vendor/bin/phpstan analyse --verbose
    

    Helps identify which rules are failing.

  • Isolate Rules: Temporarily disable other extensions to check if conflicts exist:

    includes:
        - vendor/phpstan/phpstan-symfony/extension.neon  # Try official instead
    
  • Check Symfony Version: Ensure your symfony/* packages match the package’s supported range (Symfony 3.x/4.x).

Extension Points

  • Custom Rule Creation: If you need Symfony-specific rules, fork the package and extend SymfonyExtension:
    class CustomSymfonyExtension extends \Lookyman\PHPStanSymfony\SymfonyExtension {
        public function getRuleSet(): RuleSet {
            return RuleSet::create([new CustomRule()]);
        }
    }
    
  • Rule Suppression: Suppress false positives in phpstan.neon:
    suppress:
        - Lookyman\PHPStanSymfony\Rules\InvalidServiceRule::class
    

Migration Path

If stuck with this package:

  1. Audit Dependencies: List all Symfony classes used in rules (via vendor/lookyman/phpstan-symfony/src/Rules/).
  2. Replace with Modern Alternatives:
    • Use symplify/phpstan-symfony for Symfony 4.4+.
    • For Laravel, use phpstan/phpstan-laravel.
  3. Gradual Replacement: Start by migrating rules one by one to the new extension.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky