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

Php Cs Fixer Extensions Laravel Package

slam/php-cs-fixer-extensions

Extensions and ready-to-use rulesets for FriendsOfPHP PHP-CS-Fixer. Adds custom fixers like final_abstract_public, final_internal_class, utf8 cleanup, inline comment spacing, function reference spacing, and PHP-only proxy fixers for consistent code style.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strengths:

    • Laravel-Specific Optimizations: Custom fixers like FinalAbstractPublicFixer and FinalInternalClassFixer directly address Laravel’s service container patterns and Doctrine entity handling, reducing manual code reviews.
    • UTF-8 Enforcement: The Utf8Fixer mitigates encoding-related bugs in Blade templates (*.phtml), a common pain point in Laravel projects.
    • PHP 8.x+ Alignment: Supports modern PHP features (e.g., readonly classes, PHPUnit 11) while maintaining compatibility with Laravel’s latest versions (10+).
    • Extensible Rule Set: Rules like php_only_braces and function_reference_space enforce consistency without overreach, making them suitable for teams prioritizing maintainability over strictness.
  • Weaknesses:

    • Risky Defaults: Enabling setRiskyAllowed(true) could introduce unintended refactoring (e.g., modifying abstract classes). Requires explicit opt-in for risky rules.
    • Niche Use Cases: Limited adoption (0 dependents) suggests the package may not cover all Laravel-specific edge cases (e.g., Livewire, Forge, or Vapor patterns).
    • PHP Version Dependency: PHP 8.4+ requirement may block adoption in legacy Laravel projects (e.g., LTS 8.x). Teams must weigh upgrade costs against the package’s benefits.

Technical Risk

  • Low-Medium:
    • Integration Risk: Minimal if PHP-CS-Fixer is already in use. High if the team lacks CS tooling experience.
    • False Positives: Custom fixers (e.g., FinalInternalClassFixer) may conflict with Laravel’s conventions (e.g., repository classes). Requires pre-adoption testing.
    • Maintenance Risk: Active development (monthly releases) reduces long-term risk, but dependency on php-cs-fixer v3.x+ means breaking changes could occur.
    • Performance Risk: Negligible for most projects; PHP-CS-Fixer is optimized for speed.

Key Questions for TPM

  1. Alignment with Team Needs:

    • Does the team experience UTF-8 encoding issues in Blade templates or legacy code?
    • Are abstract class finality or Doctrine entity formatting recurring PR bottlenecks?
    • Is the team migrating to PHP 8.4+ or Laravel 10+? If not, is the upgrade justified by this package?
  2. Adoption Feasibility:

    • Is PHP-CS-Fixer already integrated into CI/CD? If not, what’s the effort to add it?
    • Can the team test all custom fixers in a staging environment before full adoption?
    • Are there existing CS tools (e.g., custom scripts, ESLint) that would conflict with this package?
  3. Long-Term Viability:

    • How will the team handle breaking changes in php-cs-fixer v3.x+?
    • Is there a maintenance plan for the package if the upstream (Slamdunk) project becomes inactive?
    • Will the package’s custom rules scale with Laravel’s evolving patterns (e.g., Livewire, Jetstream)?
  4. Trade-offs:

    • Should the team opt out of risky rules (e.g., FinalAbstractPublicFixer) to avoid false positives?
    • Is the additional dependency bloat (PHPUnit, PHPStan) acceptable for dev environments?
    • Would a subset of rules (e.g., only Utf8Fixer) provide sufficient value to justify adoption?

Integration Approach

Stack Fit

  • Ideal Stack:

    • Laravel 10+ with PHP 8.4+.
    • PHP-CS-Fixer (v3.x+) already integrated into CI/CD (e.g., GitHub Actions, GitLab CI).
    • Blade templates (*.phtml) or mixed PHP/HTML files requiring UTF-8 enforcement.
    • Doctrine ORM or custom repositories needing consistent formatting.
    • PHPUnit 10/11 or PHPStan for static analysis.
  • Compatibility Notes:

    • Laravel < 10: May require additional testing for Doctrine entity fixers.
    • PHP < 8.4: Incompatible; requires upgrade or alternative solutions.
    • Non-Laravel PHP: Some fixers (e.g., FinalAbstractPublicFixer) are Laravel-agnostic but may not address framework-specific needs.

Migration Path

  1. Assessment Phase (1–2 days):

    • Audit existing .php_cs config and identify conflicts.
    • Test custom fixers on a sample codebase (e.g., a Laravel monorepo subset).
    • Validate UTF-8 encoding and Doctrine entity handling in the team’s codebase.
  2. Pilot Phase (3–5 days):

    • Install the package in a staging environment:
      composer require --dev slam/php-cs-fixer-extensions
      
    • Update .php_cs to include custom fixers (example provided in README).
    • Run PHP-CS-Fixer locally and in CI to catch issues early:
      ./vendor/bin/php-cs-fixer fix --dry-run --diff
      
  3. Full Adoption (1 week):

    • Merge .php_cs changes into the main branch.
    • Gate PHP-CS-Fixer in pre-commit hooks (e.g., using php-cs-fixer CLI or Laravel Pint).
    • Train developers on custom rule exceptions (e.g., when to disable FinalAbstractPublicFixer).

Sequencing

  • Prerequisites:

    • PHP-CS-Fixer must be installed and configured in the project.
    • CI/CD pipeline must support custom PHP-CS-Fixer rules (no blacklists).
    • Team must agree on risk tolerance for setRiskyAllowed(true).
  • Recommended Order:

    1. Start with safe rules: Enable Utf8Fixer, function_reference_space, and inline_comment_spacer.
    2. Add Laravel-specific rules: Test FinalAbstractPublicFixer and FinalInternalClassFixer in isolation.
    3. Enable risky rules last: Only after validating no false positives (e.g., in repository classes).
    4. Integrate with CI: Fail builds on violations, then gradually enforce fixes.

Compatibility

  • Conflicts to Address:
    • Custom CS Tools: If the team uses alternative formatters (e.g., Laravel Pint), evaluate overlap or merge strategies.
    • Legacy Code: Some fixers (e.g., FinalAbstractPublicFixer) may break existing abstract classes. Use --dry-run to identify risks.
    • Monorepos: Ensure the package works across all PHP versions in the repo (e.g., Laravel + legacy PHP 7.4 modules).

Operational Impact

Maintenance

  • Pros:

    • Low Effort: No ongoing maintenance required beyond PHP-CS-Fixer updates.
    • Automated Fixes: Rules like Utf8Fixer and php_only_braces reduce manual code reviews.
    • Community Support: Active development (monthly releases) and MIT license ensure long-term viability.
  • Cons:

    • Dependency Updates: Requires monitoring php-cs-fixer and this package for breaking changes.
    • Rule Tuning: May need to disable or adjust fixers as Laravel evolves (e.g., new attribute patterns).
    • Documentation: Team must document why custom rules are enabled (e.g., "We use FinalAbstractPublicFixer to prevent service container leaks").

Support

  • Developer Onboarding:
    • Pros: Standardized formatting reduces friction for new hires.
    • Cons: Custom rules may require additional training (e.g., "Why are abstract methods marked final?").
  • Troubleshooting:
    • Common Issues:
      • False positives in Doctrine entities (e.g., FinalInternalClassFixer).
      • UTF-8 encoding failures in legacy Blade templates.
    • Mitigations:
      • Provide a .php_cs.override file for exceptions.
      • Document known edge cases in the team’s CS guidelines.

Scaling

  • Performance:
    • Negligible Impact: PHP-CS-Fixer is optimized for speed; custom fixers add minimal overhead.
    • Large Codebases: May slow down CI if not cached (use php-cs-fixer cache:clear).
  • Team Growth:
    • Scalable: Rules enforce consistency across teams and repositories.
    • Customization: Teams can fork the package or extend rules for project-specific needs.

Failure Modes

Failure Scenario Impact Mitigation
PHP-CS-Fixer breaking change Build failures Pin to a specific version in composer.json.
False positives in production code Developer frustration Test in staging; use --dry-run pre-merge.
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.
cadot.eu/make
besmartand-pro/php-quality-config
sentix/ai-chatbot
codifyo/ts-generator-bundle
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