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

Code Style Php Laravel Package

chiiya/code-style-php

Reusable code style configs for PHP 8.1+ projects, combining PHP-CS-Fixer, EasyCodingStandard (ECS), and Rector. Install via Composer and import the provided rule sets into your tool config files to standardize formatting and refactors.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Laravel Alignment: The package is explicitly designed for PHP projects, not Laravel-specific, but integrates seamlessly with Laravel’s ecosystem (e.g., PHP-CS-Fixer, ECS, Rector). The Laravel-specific variant (laravel-code-style) suggests this package is a foundational layer.
  • Toolchain Compatibility: Leverages PHP-CS-Fixer, ECS (Easy Coding Standard), and Rector, which are already common in Laravel projects for linting, static analysis, and refactoring. This reduces friction for adoption.
  • Customizability: The package provides pre-configured rules but allows overrides, making it adaptable to Laravel’s evolving standards (e.g., custom PSR-12 variants, framework-specific conventions).

Integration Feasibility

  • Low-Coupling: The package is configuration-only (no runtime dependencies), making it non-intrusive. It can be adopted incrementally without disrupting existing workflows.
  • CI/CD Readiness: Works natively with GrumPHP (dev dependency), which is widely used in Laravel projects for pre-commit hooks and CI pipelines (e.g., GitHub Actions, GitLab CI).
  • Toolchain Synergy:
    • PHP-CS-Fixer: Aligns with Laravel’s default .php-cs-fixer.dist.php.
    • ECS: Complements Laravel’s growing adoption of Easy Coding Standard for extensible linting.
    • Rector: Enables safe, automated refactoring (e.g., upgrading legacy code), which is valuable for large Laravel monorepos.

Technical Risk

  • Dependency Versioning:
    • Requires PHP 8.2+ (may conflict with legacy Laravel 8.x projects).
    • Tight coupling to specific versions of PHP-CS-Fixer (3.68), Rector (2.0), and ECS (13.0) could lead to compatibility issues if the package lags in updates.
    • Mitigation: Pin versions explicitly in composer.json and monitor upstream updates.
  • Rule Conflicts:
    • Some rules (e.g., OrderedClassElementsFixer) were removed due to false positives. Laravel-specific rules (e.g., for Facades, Blade templates) may need manual tuning.
    • Mitigation: Test against a Laravel codebase early and override problematic rules.
  • Performance Overhead:
    • Rector’s refactoring rules may introduce runtime analysis during composer install or CI, slowing down pipelines.
    • Mitigation: Run Rector separately in CI (e.g., only on main branch).

Key Questions

  1. Laravel-Specific Needs:
    • Does the team need Laravel-specific rules (e.g., for Blade templates, Facade usage, or Eloquent models)? If so, the standalone package may require extensions, or the laravel-code-style fork should be prioritized.
  2. CI/CD Pipeline Impact:
    • How will this integrate with existing linting tools (e.g., PSalm, Pint)? Will it replace, complement, or conflict with them?
  3. Developer Adoption:
    • Will the team accept the stricter rules (e.g., Rector’s refactoring)? If resistance is expected, focus on PHP-CS-Fixer/ECS first.
  4. Long-Term Maintenance:
    • Who will monitor updates to the package and its dependencies? Will the team fork if the package stagnates?

Integration Approach

Stack Fit

  • Core Tools:
    • PHP-CS-Fixer: Replace or extend Laravel’s default config (.php-cs-fixer.dist.php).
    • ECS: Integrate with GrumPHP for pre-commit checks or CI validation.
    • Rector: Use for safe refactoring (e.g., upgrading str_replace to Str::replace) in CI or via a script.
  • Laravel Ecosystem:
    • Works alongside Laravel Pint (if used) but can be configured to avoid duplication.
    • Compatible with Laravel Forge/Envoyer for deployment-time linting.
  • Alternatives:
    • If the team uses custom linting tools, assess whether this package’s rules align or require merging.

Migration Path

  1. Phase 1: Adoption
    • Install the package in dev dependencies:
      composer require chiiya/code-style-php --dev
      
    • Replace .php-cs-fixer.dist.php with the package’s config (or merge rules).
    • Add ECS config (ecs.php) and Rector config (rector.php) to composer.json:
      "extra": {
        "ecs": ["vendor/bin/ecs check src"]
      }
      
  2. Phase 2: CI/CD Integration
    • Add GrumPHP to CI (e.g., GitHub Actions):
      - name: Run ECS
        run: vendor/bin/ecs check --config=ecs.php src
      
    • Run Rector in a separate job (optional):
      - name: Run Rector
        run: vendor/bin/rector process src --dry-run
      
  3. Phase 3: Enforcement
    • Enable pre-commit hooks (via Husky + GrumPHP).
    • Gradually introduce Rector rules in CI (start with --dry-run).

Compatibility

  • PHP Version: Requires 8.2+ (blocker for Laravel <8.97).
  • Toolchain Conflicts:
    • Avoid mixing with Pint (use either PHP-CS-Fixer or Pint, not both).
    • Ensure PSR-12 compliance if using Laravel’s default rules.
  • Custom Rules: Override any conflicting rules in ecs.php or rector.php:
    // ecs.php
    return ECSConfig::fromPhpStormConfig()
        ->withRules([
            new NoUnusedPhpDocTagsRule(),
            // Override default rules
        ]);
    

Sequencing

  1. Start with PHP-CS-Fixer/ECS (low risk, high visibility).
  2. Add Rector incrementally (focus on non-breaking changes first).
  3. Leverage Laravel-specific fork if needed (e.g., for Blade/Facade rules).
  4. Automate in CI before enforcing locally (reduce friction).

Operational Impact

Maintenance

  • Dependency Updates:
    • Monitor PHP-CS-Fixer, Rector, and ECS for breaking changes.
    • Pin versions in composer.json to avoid surprises:
      "config": {
        "allow-plugins": {
          "friendsofphp/php-cs-fixer": true
        }
      }
      
  • Rule Maintenance:
    • Override or disable rules that cause false positives (document changes).
    • Contribute fixes upstream if rules are universally problematic.
  • Documentation:
    • Maintain a CONTRIBUTING.md or CODE_STYLE.md in the repo to explain:
      • Why specific rules are used/overridden.
      • How to run linting/refactoring locally.

Support

  • Onboarding:
    • Provide a cheat sheet for running tools:
      # Fix PHP-CS-Fixer issues
      composer run fix-cs
      
      # Run ECS
      composer run lint
      
      # Apply Rector refactoring (dry-run)
      composer run rector
      
    • Train teams on reading ECS/Rector output (e.g., interpreting Rector’s diffs).
  • Troubleshooting:
    • Common issues:
      • False positives in ECS (e.g., Blade templates misclassified as PHP).
      • Rector breaking changes (always test with --dry-run).
    • Solution: Maintain a FAQ or runbook for the team.

Scaling

  • Performance:
    • ECS/PHP-CS-Fixer: Linear with codebase size. For large repos, exclude vendor/ and node_modules/:
      return ECSConfig::fromPhpStormConfig()
          ->withPaths(['src', 'tests']);
      
    • Rector: Can be memory-intensive. Use --parallel and limit to specific paths.
  • Parallelization:
    • Run ECS/PHP-CS-Fixer in CI in parallel with other tests.
    • Use GitHub Actions’ matrix strategy to split Rector jobs by directory.
  • Distributed Teams:
    • Enforce rules in CI first to avoid local inconsistencies.
    • Use pre-commit hooks (Husky + GrumPHP) only after team alignment.

Failure Modes

Failure Mode Impact Mitigation
Strict rules block PRs Slows down development. Start with `--
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