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

Coding Standard Laravel Package

sylius-labs/coding-standard

Battle-tested Sylius coding standard for PHP. Install via Composer and import the provided ecs.php into your EasyCodingStandard (ECS) config to apply consistent formatting and rules across your project. Includes guidance for migrating from YAML to PHP configs.

View on GitHub
Deep Wiki
Context7
## Getting Started
### Minimal Steps
1. **Installation**
   Run:
   ```bash
   composer require --dev sylius-labs/coding-standard:^4.5

This updates the Sylius coding standard to the latest version (v4.5.1) as a dev dependency.

  1. Basic Integration In your ecs.php (EasyCodingStandard config file), import the Sylius rules:

    $ecsConfig->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php');
    
  2. First Use Case Run the linter on your project:

    vendor/bin/ecs check src tests
    

    Fix issues automatically (where possible):

    vendor/bin/ecs fix src tests
    
  3. Where to Look First


Implementation Patterns

Usage Patterns

  1. Project-Wide Standardization Use the Sylius coding standard to enforce consistency across:

    • Core Laravel applications (e.g., src/, app/).
    • Test suites (e.g., tests/).
    • Custom packages or modules.
  2. Custom Rule Overrides Extend or override Sylius rules in your ecs.php:

    $ecsConfig->import(__DIR__ . '/vendor/sylius-labs/coding-standard/ecs.php');
    $ecsConfig->ruleWithConfiguration(Symplify\EasyCodingStandard\ValueObject\Option\SetList::class, [
        SetList::SYLIUS => true,
        SetList::PSR_12 => true, // Add PSR-12 for broader compatibility
    ]);
    
  3. CI/CD Integration Add ECS checks to your pipeline (e.g., GitHub Actions):

    - name: Run ECS
      run: vendor/bin/ecs check src tests --ansi
    

    Fail the build on violations:

    - name: Enforce ECS
      run: vendor/bin/ecs check src tests --ansi --no-interaction --error-format=github
    
  4. Pre-Commit Hooks Use ecs with tools like PHP-CS-Fixer or Husky to catch issues early:

    composer require --dev php-cs-fixer
    vendor/bin/php-cs-fixer fix --rules=@Sylius --dry-run
    
  5. Team Onboarding Document the coding standard in your CONTRIBUTING.md:

    ## Code Style
    We use the [Sylius Coding Standard](https://github.com/SyliusLabs/CodingStandard) (v4.5.1).
    Run `composer lint` to check your changes.
    

Workflows

  1. Daily Development

    • Run composer lint (alias for ecs check) before committing.
    • Use ecs fix to auto-correct common issues (e.g., spacing, docblocks).
  2. Pull Request Reviews

  3. Legacy Code Migration

    • Gradually adopt the standard by:
      1. Running ecs check to identify violations.
      2. Fixing critical issues (e.g., security, readability).
      3. Using --parallel for large codebases:
        vendor/bin/ecs check src --parallel=4
        
  4. Custom Rule Sets

    • Create project-specific rules by extending the Sylius config:
      $ecsConfig->ruleWithConfiguration(
          Symplify\EasyCodingStandard\ValueObject\Option\ParallelOption::class,
          true
      );
      $ecsConfig->ruleWithConfiguration(
          Symplify\EasyCodingStandard\ValueObject\Option\PathsOption::class,
          [__DIR__ . '/src', __DIR__ . '/tests']
      );
      

Gotchas and Tips

Pitfalls

  1. ECS Version Conflict (NEW)

    • Issue: Sylius Coding Standard v4.5.1 introduces a conflict with EasyCodingStandard v13.1.3+. If you upgrade ECS to >=13.1.3, you must either:
      • Downgrade ECS to <13.1.3:
        composer require symplify/easy-coding-standard:^13.0
        
      • Or update Sylius Coding Standard to a future version that resolves the conflict.
    • Workaround: Pin ECS to a compatible version in composer.json:
      {
        "require-dev": {
          "symplify/easy-coding-standard": "^12.0"
        }
      }
      
  2. Rule Conflicts

    • Sylius’ standard may conflict with other tools (e.g., PHPStan, Psalm).
    • Fix: Explicitly define rule priorities in ecs.php:
      $ecsConfig->ruleWithConfiguration(
          Symplify\EasyCodingStandard\ValueObject\Option\ParallelOption::class,
          true
      )->ruleWithConfiguration(
          Symplify\EasyCodingStandard\ValueObject\Option\SetList::class,
          [SetList::SYLIUS => true, SetList::PSR_12 => false]
      );
      
  3. Performance with Large Codebases

    • Running ECS on src/ + tests/ can be slow.
    • Tip: Use --parallel or exclude specific paths:
      vendor/bin/ecs check src --exclude=src/Migrations
      
  4. False Positives

    • Sylius rules may flag legitimate patterns (e.g., magic methods, dynamic properties).
    • Fix: Disable specific rules:
      $ecsConfig->ruleWithConfiguration(
          Symplify\EasyCodingStandard\ValueObject\Option\Skip::class,
          [__DIR__ . '/src/Some/Class.php']
      );
      
  5. YML to PHP Migration

    • If upgrading from .ecs.yml, use config-transformer:
      composer require --dev symplify/config-transformer
      vendor/bin/config-transformer transform .ecs.yml ecs.php
      

Debugging

  1. Verbose Output Run ECS with --verbose to debug rule application:

    vendor/bin/ecs check src --verbose
    
  2. Dry Runs Use --dry-run to preview changes:

    vendor/bin/ecs fix src --dry-run
    
  3. Rule-Specific Debugging Isolate rule issues by running a single rule set:

    vendor/bin/ecs check src --config=vendor/sylius-labs/coding-standard/rules/arrays.php
    
  4. ECS Version Debugging (NEW) If you encounter conflicts, check versions with:

    composer show symplify/easy-coding-standard sylius-labs/coding-standard
    

    Ensure compatibility by pinning versions in composer.json.


Tips

  1. Custom Aliases Add a composer.json script for quick access:

    {
      "scripts": {
        "lint": "ecs check src tests",
        "lint:fix": "ecs fix src tests"
      }
    }
    
  2. Partial Adoption Start with a subset of rules (e.g., only arrays, docblocks):

    $ecsConfig->ruleWithConfiguration(
        Symplify\EasyCodingStandard\ValueObject\Option\SetList::class,
        [SetList::SYLIUS_ARRAYS => true]
    );
    
  3. Sylius-Specific Rules Leverage Sylius’ Laravel-focused rules (e.g., laravel-controller):

    $ecsConfig->ruleWithConfiguration(
        Symplify\EasyCodingStandard\ValueObject\Option\ParallelOption::class,
        true
    )->ruleWithConfiguration(
        Symplify\EasyCodingStandard\ValueObject\Option\SetList::class,
        [SetList::SYLIUS_LARAVEL => true
    
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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui