Weave 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

Robo Phpstan Laravel Package

sweetchuck/robo-phpstan

Robo tasks for running PHPStan in your PHP projects. Provides configurable commands and integration helpers to execute static analysis as part of Robo workflows and CI pipelines, with options for paths, config files, and reporting.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require --dev sweetchuck/robo-phpstan
    

    Ensure robo/robo is also installed (required dependency).

  2. First Use Case: Add a phpstan.neon config file in your project root (or extend an existing one). Run a basic analysis:

    vendor/bin/robo phpstan:analyse
    

    This executes PHPStan with default parameters (level 5, autoload from composer.json).

  3. Where to Look First:

    • Review robo.php for predefined tasks (if any).
    • Check src/Robo/Tasks/PHPStanTasks.php for available commands (e.g., analyse, bootstrap, check).
    • Default config: phpstan.neon (or phpstan.dist.neon for templates).

Implementation Patterns

Common Workflows

  1. Integrate into CI/CD: Add to .github/workflows/phpstan.yml or similar:

    - name: Run PHPStan
      run: vendor/bin/robo phpstan:analyse --level=7
    

    Use --no-progress for cleaner CI output.

  2. Customize Analysis: Extend phpstan.neon to include:

    includes:
      - vendor/autoload.php
      - config/phpstan.php
    parameters:
      level: 8
      paths:
        - src
        - tests
    
  3. Task Chaining: Combine with other Robo tasks (e.g., phpstan:bootstrap before analysis):

    $this->taskPHPStanBootstrap()
         ->run();
    $this->taskPHPStanAnalyse()
         ->run();
    
  4. Parallel Execution: Use --parallel flag for multi-core analysis:

    vendor/bin/robo phpstan:analyse --parallel
    

Integration Tips

  • Laravel-Specific: Add Laravel-specific paths to phpstan.neon:
    paths:
      - app
      - bootstrap
      - config
      - database/seeds
      - routes
    
  • Exclude Files: Use excludeFiles in phpstan.neon to skip tests or generated files:
    excludeFiles:
      - '*/Tests/*'
      - '*/Migrations/*'
    
  • Template Projects: Use phpstan.dist.neon as a template for new projects.

Gotchas and Tips

Pitfalls

  1. Missing Autoload: If PHPStan fails to load classes, ensure includes in phpstan.neon points to vendor/autoload.php or use:

    vendor/bin/robo phpstan:bootstrap
    
  2. Level Mismatch: Default level is 5. For stricter checks, explicitly set --level=8 or higher in phpstan.neon.

  3. Configuration Overrides: Command-line flags (e.g., --level) override phpstan.neon settings. Use --no-cache to bypass cached results if configs change.

  4. Robo Task Not Found: Ensure robo/robo is installed. Run composer require robo/robo if missing.

Debugging

  • Verbose Output: Use --verbose for detailed logs:
    vendor/bin/robo phpstan:analyse --verbose
    
  • Check PHPStan Version: Ensure compatibility with your PHPStan version (e.g., 3.x for PHPStan 1.x).

Extension Points

  1. Custom Tasks: Extend PHPStanTasks in your robo.php:
    $this->taskPHPStanAnalyse()
         ->arg('level')->default('8')
         ->run();
    
  2. Pre/Post Hooks: Use Robo’s before()/after() to run tasks before/after PHPStan:
    $this->taskPHPStanAnalyse()
         ->before(function () {
             $this->taskExec('composer dump-autoload')->run();
         });
    
  3. Dynamic Configs: Load phpstan.neon dynamically based on environment (e.g., phpstan.prod.neon):
    $configPath = env('PHPSTAN_CONFIG') ?: 'phpstan.neon';
    $this->taskPHPStanAnalyse()->arg('config')->default($configPath)->run();
    

Tips

  • Cache Management: Clear cache with --no-cache or manually delete .phpstan.cache.
  • Git Hooks: Add a pre-commit hook to run PHPStan on staged files:
    vendor/bin/robo phpstan:analyse --paths=src --no-progress
    
  • IDE Integration: Use PHPStan’s IDE plugin (e.g., PHPStan for PHPStorm) with this package for real-time feedback.
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.
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator
equipc/laravel-email-database-log
adedsec/nova-translated-labels