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

phpyh/coding-standard

PHPyh Coding Standard provides a ready-to-use PHP CS Fixer configuration for consistent formatting across your project. Install via Composer and apply the PhpCsFixerCodingStandard to your .php-cs-fixer.dist.php, with support for overriding rules.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Purpose Alignment: The phpyh/coding-standard package (v3.0.1) remains a static analysis tool for PHP coding standards, leveraging PHP_CodeSniffer. Its non-framework-specific nature persists as both an advantage (flexibility) and limitation (redundancy risk with Laravel tools like laravel/pint or rector/rector). The new explicit support for array_destructuring and match expressions in trailing_comma_in_multiline directly addresses Laravel 10+ adoption of modern PHP syntax, particularly in:

    • Controllers (match expressions for state handling).
    • Service containers (array destructuring for dependency injection).
    • Domain logic (replacing switch with match in business layers). The deprecation fixes ensure long-term compatibility with PHP_CodeSniffer updates, critical for Laravel’s frequent dependency upgrades.
  • New Features:

    • Deprecation Fixes: Resolves deprecated rule sets, eliminating integration risks during PHP_CodeSniffer updates. This is non-negotiable for Laravel projects where tooling stability is paramount.
    • Modern PHP Syntax Support:
      • array_destructuring: Explicitly allows trailing commas in destructuring assignments (e.g., [...$items]), reducing false negatives in Laravel’s collection-based logic (e.g., collect($items)->map(fn($item) => [...$item])).
      • match expressions: Aligns with Laravel’s PHP 8.1+ adoption (e.g., match ($request->input('status')) { ... } in controllers). The rule avoids flagging Laravel’s internal match usage (e.g., in Illuminate/Support/), a critical improvement over v3.0.0.
    • Granular Configuration: New properties (allow_array_destructuring, match_expression_support) enable context-aware enforcement, ideal for Laravel’s layered architecture (e.g., strict rules for app/ but lenient for resources/views/).
  • Leverage Points (Updated):

    • Zero-Cost Modernization: Enforces PHP 8.1+ features without requiring code rewrites, accelerating Laravel upgrades.
    • Reduced Tooling Fatigue: Eliminates false positives for Laravel-specific patterns (e.g., match expressions in app/Exceptions/Handler.php).
    • CI/CD Readiness: New rules are opt-in via configuration, allowing phased adoption (e.g., warnings → errors).
    • Blade Compatibility: Explicit support for .blade.php files (via --extensions=php,blade) bridges the gap between PHP and Blade syntax.
  • Misalignment Risks (Updated):

    • Overlap with rector/rector: If rector is used for match expression refactoring, duplicate rules may emerge. Mitigation: Audit rector rules for @match annotations and disable overlapping phpyh rules.
    • Blade-Specific Edge Cases: Complex @php blocks or legacy Blade templates may trigger unintended exclusions. Mitigation: Test with --extensions=php,blade and exclude problematic paths.
    • Performance in Large Codebases: Parallelization with phpstan is recommended to avoid CI bottlenecks (e.g., 5–10s runtime for 10K+ files).

Integration Feasibility

  • Compatibility Improvements:

    • PHP 8.1+ Alignment: The explicit whitelisting of match expressions in Laravel’s core (e.g., Illuminate/Support/) prevents false positives, a blocker in v3.0.0.
    • Backward Compatibility: Deprecation fixes ensure no breaking changes during PHP_CodeSniffer updates, critical for Laravel’s dependency ecosystem.
    • Blade Support: Native handling of .blade.php files reduces pre-processing steps, simplifying CI pipelines.
  • Customization:

    • Context-Aware Rules: Configure via phpcs.xml:
      <rule ref="phpyh/trailing_comma_in_multiline">
        <properties>
          <property name="allow_array_destructuring" value="true"/> <!-- Laravel collections -->
          <property name="match_expression_support" value="true"/> <!-- Controllers -->
          <property name="exclude_match_in_illuminate" value="true"/> <!-- Skip Laravel internals -->
        </properties>
        <exclude name="resources/views/legacy/*.blade.php"/> <!-- Opt-out for old templates -->
      </rule>
      
    • Dynamic Runtime Settings: Use --runtime-set to toggle features:
      ./vendor/bin/phpcs --runtime-set testVersion=8.1 --runtime-set allowMatch=true app/
      
  • Potential Pitfalls:

    • Rule Aggressiveness: New match rules may over-enforce in projects using match expressions sparingly (e.g., experimental features). Solution: Start with --warning-severity=5.
    • Configuration Drift: Teams may diverge on property values (e.g., allow_array_destructuring). Solution: Enforce a centralized phpcs.xml template.
    • Blade Parsing Quirks: Complex @php blocks or nested directives may bypass rules. Solution: Test with --extensions=php,blade and adjust exclusions.

Technical Risk

  • Reduced Risks:

    • Deprecation-Proof: Fixes for deprecated rule sets eliminate integration breaks during PHP_CodeSniffer updates.
    • Laravel-Specific Safety: Explicit exclusion of Laravel’s internal match expressions prevents false positives in core files.
    • Modern PHP Support: Alignment with PHP 8.1+ reduces friction in Laravel 10+ projects.
  • New Risks:

    • Rule Collisions: Overlap with rector’s @match or phpstan’s type checks. Mitigation: Audit tools for redundant rules.
    • Blade False Negatives: Legacy Blade templates may slip through if not excluded. Mitigation: Use --extensions=php,blade and explicit <exclude>.
    • CI Flakiness: New rules may fail intermittently in parallelized pipelines. Mitigation: Cache PHP_CodeSniffer results or run sequentially.
  • Critical Questions:

    1. Are match expressions used in Laravel-specific contexts (e.g., controllers, middleware)? → If yes, validate that the new match_expression_support property is enabled and Laravel internals are excluded.
    2. Does the project use rector or phpstan with overlapping match expression rules? → Audit for redundant checks and disable conflicting rules in phpyh.
    3. Should array destructuring trailing commas be mandatory for all arrays, or only in specific contexts (e.g., collections)? → Configure via <property name="allow_array_destructuring">.
    4. How are Blade templates handled? → Test with --extensions=php,blade and exclude legacy templates if needed.
    5. Is the team prepared to maintain updated phpcs.xml with new properties? → Document defaults and provide a template for onboarding.

Integration Approach

Stack Fit

  • Best For:

    • Laravel 10+ Projects: Explicit support for match expressions and destructuring eliminates friction in modern Laravel codebases.
    • Teams Adopting PHP 8.1+: Ideal for projects migrating to newer syntax (e.g., replacing switch with match in controllers).
    • Hybrid Codebases: Useful where legacy and modern PHP coexist (e.g., destructuring in service containers alongside older Blade templates).
    • CI/CD Pipelines: Lightweight (~1–3s runtime) and parallelizable with phpstan.
  • Less Ideal For:

    • Strict Laravel-Only Stacks: If using laravel/pint (formatting) + phpstan (typing), evaluate rule redundancy (e.g., trailing commas).
    • Teams Averse to Configuration: New properties (e.g., match_expression_support) require phpcs.xml adjustments.
    • Legacy Laravel (<9.x): Minimal benefit if not using PHP 8.1+ features.

Migration Path

  1. Assessment Phase:

    • Run a dry analysis to identify violations in modern PHP constructs:
      ./vendor/bin/phpcs \
        --standard=phpyh \
        --runtime-set testVersion=8.1 \
        --runtime-set allowMatch=true \
        --extensions=php,blade \
        --report=json app/ | jq '.files[] | select(.errors | length > 0)'
      
    • Focus on:
      • Match expressions in app/Http/Controllers/ or app/Exceptions/.
      • Array destructuring in app/Services/ or collection methods.
  2. Pilot:

    • Test locally with gradual enforcement:
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky