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

Standards Laravel Package

rollerscapes/standards

A standardized set of PHP code style and quality assurance rules from Rollerscapes, bundling the tooling and configuration used across all its projects, including Rollerworks, HuPKit, and Rollersearch, to keep coding standards consistent and enforce quality checks.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the package to your Laravel project:

    composer require rollerscapes/standards --dev
    

    This installs PHP-CS-Fixer, PHPStan (with Symfony/Laravel extensions), and PHPUnit configurations.

  2. First Command Run the integrated linter and static analyzer:

    php artisan standards:check
    

    This executes both PHP-CS-Fixer (auto-fixable) and PHPStan (static analysis) in a single pass.

  3. Where to Look First

    • Configuration: Check config/standards.php (auto-generated on first run) for customizable rules (PHP-CS-Fixer, PHPStan levels, excluded paths).
    • Makefile: Use provided shortcuts:
      make lint      # Runs PHP-CS-Fixer
      make stan      # Runs PHPStan
      make test      # Runs PHPUnit with internal test checks
      
    • Git Hooks: Enable pre-commit checks:
      php artisan standards:git-hook
      

Implementation Patterns

Usage Patterns

  1. Daily Development Workflow

    • Auto-Fix Style Issues:
      php artisan standards:fix
      
      Applies PHP-CS-Fixer rules (e.g., PSR-12 compliance, PHPDoc alignment) to staged files.
    • Static Analysis on Demand:
      php artisan standards:analyze --level=5
      
      Runs PHPStan with a custom strictness level (default: max).
    • Focused Checks:
      php artisan standards:check app/Http/Controllers
      
      Targets specific directories (e.g., controllers, services).
  2. CI/CD Pipeline Integration

    • Fail on Violations:
      # GitHub Actions example
      - name: Enforce Standards
        run: php artisan standards:check --fail-on-errors
      
    • Cache PHPStan Results:
      php artisan standards:analyze --generate-baseline
      
      Generates a baseline file (phpstan.baseline.neon) to ignore known issues temporarily.
  3. Customization

    • Override Default Rules: Publish the config and modify config/standards.php:
      php artisan vendor:publish --provider="Rollerscapes\Standards\StandardsServiceProvider" --tag="config"
      
      Example: Adjust PHPStan’s level or exclude Laravel-specific false positives:
      'phpstan' => [
          'level' => 7, // Lower strictness for legacy code
          'exclude_paths' => [
              'app/Providers/AppServiceProvider.php', // Skip problematic files
          ],
      ],
      
    • Extend PHPStan: Add custom rules by including a project-specific phpstan.neon:
      includes:
        - vendor/rollerscapes/standards/phpstan.neon
        - phpstan.neon  # Your custom rules
      
  4. Laravel-Specific Patterns

    • Blade Template Checks: Use PHPStan’s Symfony extension to analyze Blade files (if supported):
      php artisan standards:analyze --include-tests --include-blade
      
    • Eloquent/Database Rules: Leverage phpstan/phpstan-doctrine for Doctrine/Laravel Eloquent checks (included by default).
  5. Team Collaboration

    • Onboarding Script:
      php artisan standards:init
      
      Sets up the package, config, and Git hooks in one command.
    • Shared Baseline: Commit phpstan.baseline.neon to the repo to track known issues across contributors.

Integration Tips

  1. With Laravel Pint Replace or supplement Pint by configuring PHP-CS-Fixer in config/standards.php:

    'php-cs-fixer' => [
        'rules' => [
            '@PSR12' => true,
            'no_unused_imports' => true, // Add Laravel-specific rules
        ],
    ],
    

    Run via:

    php artisan standards:fix
    
  2. With Laravel Forge/Envoyer Add a deploy hook to run standards checks:

    php artisan standards:check --fail-on-errors
    
  3. With PHPUnit The package enforces internal test marking (e.g., @internal annotations). Update tests:

    /**
     * @internal
     */
    class ExampleTest extends TestCase { ... }
    
  4. With IDE Support Configure PHPStan in your IDE (e.g., PHPStorm) to use the project’s phpstan.neon for real-time feedback.


Gotchas and Tips

Pitfalls

  1. PHPStan Strictness

    • Issue: Upgrading to level=max may break legacy Laravel code (e.g., dynamic properties, loose typing).
    • Fix: Start with level=5 and incrementally increase strictness:
      php artisan standards:analyze --level=5
      
  2. Laravel-Specific False Positives

    • Issue: PHPStan’s Symfony extension may flag Laravel-specific code (e.g., Facades, Service Providers) as errors.
    • Fix: Exclude problematic paths in config/standards.php:
      'phpstan' => [
          'exclude_paths' => [
              'app/Providers/*',
              'routes/*',
          ],
      ],
      
    • Alternative: Use ignoreErrors in phpstan.neon:
      parameters:
        ignoreErrors:
          - '#Method Illuminate\\\\Foundation\\\\Application::bind should not be private#'
      
  3. PHP-CS-Fixer Conflicts

    • Issue: Custom Pint rules may conflict with Rollerscapes’ PHP-CS-Fixer config.
    • Fix: Merge configs by publishing and overriding:
      php artisan vendor:publish --tag=php-cs-fixer
      
      Then edit .php-cs-fixer.dist.php to prioritize project-specific rules.
  4. Performance Overhead

    • Issue: PHPStan’s level=max can slow down CI/CD pipelines for large codebases.
    • Fix:
      • Cache results with --generate-baseline.
      • Run in parallel (if supported):
        php artisan standards:analyze --parallel
        
  5. Git Hooks

    • Issue: Pre-commit hooks may fail due to unstaged changes or large files.
    • Fix: Use --allow-runtime-errors for non-critical checks:
      php artisan standards:git-hook --allow-runtime-errors
      

Debugging Tips

  1. Verbose Output Run with -v for detailed logs:

    php artisan standards:check -v
    
  2. Isolate Issues Target specific files or directories:

    php artisan standards:analyze app/Http/Controllers/UserController.php
    
  3. PHPStan Error Codes Look up errors in the PHPStan documentation or use:

    php artisan standards:analyze --error-format=github
    
  4. Configuration Validation Validate your config/standards.php:

    php artisan standards:validate-config
    

Extension Points

  1. Custom PHPStan Rules Add project-specific rules by extending the config:

    # phpstan.neon
    includes:
      - vendor/rollerscapes/standards/phpstan.neon
      - rules/custom.neon  # Your custom rules
    
  2. Dynamic Rules Use PHPStan’s parameters to conditionally enable rules:

    parameters:
      level: 7
      checkMissingIterableValueType: true
    
  3. Hooks and Events Extend the package’s Artisan commands by binding to its events (if supported). Example:

    // app/Providers/StandardsServiceProvider.php
    public function boot()
    {
        Standards::extend(function ($command) {
            $command->listen('before-check', function () {
                // Pre-check logic (e.g., log start time)
            });
        });
    }
    
  4. Forking the Package If Rollerscapes stops maintaining the package, fork it and:

    • Add Laravel-specific rules (e.g., for Blade, Eloquent).
    • Update the Makefile to include Laravel-specific tasks.
    • Publish a custom version to Packagist.

Configuration Quirks

  1. PHP Version Mismatch

    • The package requires PHP 8.1+. If using PHP 8.0, downgrade PHPStan via composer.json:
      "require-dev": {
          "phpstan/phpstan": "1.10.0" // PHP 8.0 compatible
      }
      
  2. **Doct

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.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel