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

Phpcodesniffer Composer Installer Laravel Package

dealerdirect/phpcodesniffer-composer-installer

Composer installer plugin that automatically registers PHP_CodeSniffer coding standards (rulesets) from your dependencies. It scans installed packages for phpcodesniffer-standard rulesets and configures PHPCS installed_paths—no symlinks or manual setup.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Leverages Composer Ecosystem: Aligns seamlessly with Laravel’s dependency management via Composer, requiring no custom build tooling or PHP extensions.
  • Plugin-Based Design: Operates as a Composer plugin, avoiding direct Laravel core modifications. Integrates via composer.json configuration, adhering to Laravel’s modularity.
  • Standards-Agnostic: Supports any PHP_CodeSniffer-compatible standard (e.g., PSR12, WordPress, custom), making it versatile for Laravel projects with diverse coding conventions.
  • Post-Install Hooks: Can be triggered via Composer scripts (e.g., post-install-cmd), enabling integration with Laravel’s post-update-cmd or CI/CD pipelines.

Integration Feasibility

  • Low Friction: Requires only a composer require --dev and allow-plugins configuration—no Laravel-specific setup.
  • Laravel-Specific Considerations:
    • Artisan Integration: Can be extended to add custom Artisan commands (e.g., php artisan phpcs:run) to run PHPCS with installed standards.
    • CI/CD: Native support for GitHub Actions, GitLab CI, etc., via Composer scripts (e.g., composer run-script install-codestandards).
  • Dependency Conflicts: Risk of version mismatches with phpcodesniffer-standard packages (mitigated by flexible version constraints like * or ^0.4.1 || ^0.5).

Technical Risk

  • Composer Plugin Permissions: Requires explicit allow-plugins configuration (Composer 2.2+). Global installations may conflict with project-specific versions.
  • Path Resolution: Relative paths for local standards may break if Laravel’s vendor/ directory structure changes (e.g., custom paths in config/filesystems.php).
  • Performance: Scanning for standards in large monorepos (depth >3) could slow composer install (configurable via extra.phpcodesniffer-search-depth).
  • PHP_CodeSniffer Versioning: Laravel projects using PHP 8.x must ensure PHPCS 4.x compatibility (plugin supports both).

Key Questions

  1. Standard Prioritization: How should conflicts between multiple installed standards (e.g., PSR12 vs. custom) be resolved? (Default: Last-in-wins.)
  2. CI/CD Integration: Should the plugin trigger automatically in CI, or require explicit commands (e.g., composer run-script phpcs)?
  3. Custom Standards: How will custom Laravel-specific standards (e.g., Blade templates) be packaged and distributed?
  4. Artisan Wrapping: Should PHPCS commands be wrapped in Laravel’s Artisan for consistency (e.g., php artisan phpcs:fix)?
  5. Global vs. Local: Will the plugin be installed globally (risking version conflicts) or per-project?

Integration Approach

Stack Fit

  • Composer-Centric: Ideal for Laravel’s PHP-centric stack. No Node.js/JS dependencies or Laravel-specific hooks required.
  • PHPCS Compatibility: Works with Laravel’s existing PHPCS usage (e.g., vendor/bin/phpcs) without modification.
  • Toolchain Synergy:
    • CI/CD: Integrates with Laravel Forge, Envoyer, or custom pipelines via Composer scripts.
    • IDE: Standards auto-configured in PHPStorm/VSCode via PHPCS, reducing manual setup.
    • Testing: Can be tied to phpunit.xml for pre-commit hooks (e.g., phpcs checks before tests run).

Migration Path

  1. Phase 1: Proof of Concept

    • Install in a non-production Laravel repo:
      composer require --dev dealerdirect/phpcodesniffer-composer-installer
      composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
      
    • Add a phpcodesniffer-standard package (e.g., slevomat/coding-standard):
      composer require --dev slevomat/coding-standard
      
    • Verify with:
      ./vendor/bin/phpcs -i  # List installed standards
      ./vendor/bin/phpcs app/  # Test compliance
      
  2. Phase 2: CI/CD Integration

    • Add to composer.json scripts:
      "scripts": {
        "post-install-cmd": ["@install-codestandards"],
        "post-update-cmd": ["@install-codestandards"]
      }
      
    • Configure CI (e.g., GitHub Actions) to run composer install --no-dev followed by PHPCS checks.
  3. Phase 3: Artisan Integration (Optional)

    • Create a custom Artisan command (e.g., app/Console/Commands/PhpcsCommand.php):
      public function handle()
      {
          $this->call('vendor:publish', ['--provider' => 'PHPCSStandards\Composer\Plugin\Installers\PHPCodeSniffer\Plugin']);
          $this->info('PHPCS standards installed. Run `phpcs` directly.');
      }
      
    • Register in app/Console/Kernel.php:
      protected $commands = [
          Commands\PhpcsCommand::class,
      ];
      

Compatibility

  • Laravel Versions: Compatible with Laravel 8+ (PHP 7.4+) and 9/10 (PHP 8.x). No Laravel-specific dependencies.
  • PHPCS Versions: Supports PHPCS 3.x/4.x. Laravel projects using PHPCS 2.x will need migration.
  • Composer: Requires Composer 2.2+. Laravel’s default Composer version (2.5+) meets this.
  • Custom Standards: Standards must be packaged as type: phpcodesniffer-standard per spec.

Sequencing

  1. Dependency Installation: Add dealerdirect/phpcodesniffer-composer-installer and phpcodesniffer-standard packages to composer.json.
  2. Configuration: Set allow-plugins and optional extra.phpcodesniffer-search-depth.
  3. Trigger: Run composer install or composer update to auto-configure PHPCS.
  4. Validation: Test with ./vendor/bin/phpcs -i and integrate into CI/CD.
  5. Artisan (Optional): Extend with custom commands for Laravel-specific workflows.

Operational Impact

Maintenance

  • Plugin Updates: Monitor for breaking changes (e.g., PHPCS 4.x support in v0.7.0). Laravel’s composer.json can pin versions:
    "dealerdirect/phpcodesniffer-composer-installer": "^1.0"
    
  • Standard Updates: Dependencies like slevomat/coding-standard may require version bumps.
  • Debugging: Issues with missing standards or paths can be diagnosed via:
    composer run-script install-codestandards -- --verbose
    

Support

  • Troubleshooting:
    • Permission Errors: Ensure allow-plugins is configured and Composer 2.2+ is used.
    • Path Issues: Verify standards are in vendor/ or adjust search-depth.
    • CI Failures: Cache vendor/ between runs to avoid re-scanning.
  • Documentation: Maintain a CONTRIBUTING.md or DEVELOPMENT.md in the Laravel repo detailing:
    • PHPCS setup for new devs.
    • How to add/update standards.
    • CI/CD configuration snippets.

Scaling

  • Performance:
    • Large Repos: Increase phpcodesniffer-search-depth cautiously (default: 3).
    • CI Parallelization: Run PHPCS checks in parallel with other tests (e.g., PHPUnit).
  • Standard Volume: No known limits, but excessive standards may slow PHPCS initialization.
  • Distributed Teams: Centralize standard definitions in a shared phpcodesniffer-standard package to ensure consistency.

Failure Modes

Failure Scenario Impact Mitigation
Composer plugin blocked PHPCS standards not installed Pre-configure allow-plugins in CI/CD.
Standard package missing Broken PHPCS commands Validate composer.json dependencies.
Path resolution errors Standards not detected Use absolute paths or adjust search-depth.
PHPCS version mismatch Runtime errors Pin PHPCS version in composer.json.
CI/CD cache issues Flaky PHPCS checks Cache vendor/ directory between runs.

Ramp-Up

  • Developer Onboarding:
    • New Hires: Document PHPCS setup in the README.md (e.g., "Run composer install to auto-configure standards").
    • IDE Setup: Provide PHPCS configuration sn
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