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

Symfony2Cs Bundle Laravel Package

braincrafted/symfony2cs-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install via Composer:

    composer require braincrafted/symfony2cs-bundle:dev-master
    

    (Note: Use dev-master as the package is outdated but functional.)

  2. Enable the Bundle: Add to app/AppKernel.php:

    new Braincrafted\Bundle\Symfony2CSBundle\BraincraftedSymfony2CSBundle(),
    
  3. First Use Case: Run PHP_CodeSniffer with Symfony2 standard:

    php vendor/bin/phpcs --standard=Symfony2 src/
    

    (The bundle auto-installs the Symfony2 coding standard for PHP_CodeSniffer.)

Where to Look First


Implementation Patterns

Workflows

  1. Integrate into CI/CD: Add to .gitlab-ci.yml or .github/workflows/:

    test:phpcs:
      script:
        - php vendor/bin/phpcs --standard=Symfony2 --warning-severity=3 src/
    
  2. Customize Rules: Override default rules via phpcs.xml:

    <config name="installed_paths" value="vendor/braincrafted/symfony2cs-bundle/Symfony2"/>
    <rule ref="Symfony2">
        <exclude name="Symfony2.Arrays.ArrayPush"/>
    </rule>
    
  3. Laravel-Specific Use:

    • Artisan Command: Create a custom command to run PHPCS:
      // app/Console/Commands/RunPHPCS.php
      public function handle()
      {
          $this->call('phpcs', [
              'command' => 'run',
              '--standard' => 'Symfony2',
              '--extensions' => 'php',
              'path' => 'app/'
          ]);
      }
      
    • Register in app/Console/Kernel.php:
      protected $commands = [
          Commands\RunPHPCS::class,
      ];
      
  4. Pre-Commit Hook: Use husky or pre-commit to auto-run PHPCS:

    # .husky/pre-commit
    #!/bin/sh
    php vendor/bin/phpcs --standard=Symfony2 --colors --report=full src/ || exit 1
    

Integration Tips

  • Composer Scripts: Add to composer.json:

    "scripts": {
        "phpcs": "php vendor/bin/phpcs --standard=Symfony2 src/"
    }
    

    Run with:

    composer phpcs
    
  • IDE Integration: Configure PHPStorm to use the Symfony2 standard:

    1. Go to Settings > Languages & Frameworks > PHP > Code Sniffer.
    2. Set Default severity level to warning.
    3. Add vendor/braincrafted/symfony2cs-bundle/Symfony2 to Installed paths.

Gotchas and Tips

Pitfalls

  1. Outdated Package:

  2. Path Conflicts:

    • If PHPCS can’t find the standard, verify the path in phpcs.xml:
      <config name="installed_paths" value="vendor/braincrafted/symfony2cs-bundle/Symfony2"/>
      
    • Debug with:
      php vendor/bin/phpcs -i
      
  3. Rule Overrides:

    • Some rules (e.g., Symfony2.Arrays.ArrayPush) may be too strict for Laravel. Exclude them in phpcs.xml or create a custom standard.
  4. Composer Dependency:

    • The bundle pulls in an old version of PHP_CodeSniffer. Avoid conflicts by pinning PHPCS in composer.json:
      "require-dev": {
          "squizlabs/php_codesniffer": "^3.6"
      }
      

Debugging

  • Verbose Output:
    php vendor/bin/phpcs --standard=Symfony2 --verbose src/
    
  • Check Installed Standards:
    php vendor/bin/phpcs -i
    
  • Test a Single File:
    php vendor/bin/phpcs --standard=Symfony2 app/Http/Controllers/ExampleController.php
    

Extension Points

  1. Custom Standards: Fork the Symfony2-coding-standard repo and extend it for Laravel-specific needs (e.g., relax rules for use statements in controllers).

  2. Parallel Processing: Speed up PHPCS with parallel:

    php vendor/bin/phpcs --standard=Symfony2 --parallel=8 src/
    
  3. Git Hooks: Use pre-push to catch issues before merging:

    # .git/hooks/pre-push
    #!/bin/sh
    php vendor/bin/phpcs --standard=Symfony2 --warning-severity=3 src/ || exit 1
    
  4. Visual Studio Code: Add to .vscode/settings.json:

    "php.validate.run": "onType",
    "php.cs.fixer.rules": "@Symfony",
    "php.cs.snifferConfigPath": "vendor/braincrafted/symfony2cs-bundle/Symfony2/phpcs.xml"
    
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.
nasirkhan/laravel-sharekit
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony