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 Config Laravel Package

prooph/php-cs-fixer-config

Shared PHP-CS-Fixer configuration from the prooph team. Provides a ready-to-use ruleset and presets to keep PHP code style consistent across projects, with an easy way to apply and maintain formatting standards in CI or local development.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Steps

  1. Installation Add the package to your project via Composer:

    composer require --dev prooph/php-cs-fixer-config
    

    Ensure php-cs-fixer is also installed:

    composer require --dev friendsofphp/php-cs-fixer
    
  2. First Use Case Run PHP CS Fixer with the Prooph config in your project root:

    vendor/bin/php-cs-fixer fix --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
    

    For a dry run (check without fixing):

    vendor/bin/php-cs-fixer fix --dry-run --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
    
  3. Where to Look First

    • Review the config file at vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php to understand Prooph’s coding standards (e.g., PSR-12 with Prooph-specific rules).
    • Check the PHP CS Fixer docs for rule explanations.

Implementation Patterns

Usage Patterns

  1. Integrate into CI/CD Add PHP CS Fixer to your pipeline (e.g., GitHub Actions, GitLab CI) to enforce consistency:

    # Example GitHub Actions step
    - name: Run PHP CS Fixer
      run: vendor/bin/php-cs-fixer fix --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php --diff
    
  2. Customize the Config Extend the Prooph config in your project’s php-cs-fixer.dist.php:

    <?php
    return (new PhpCsFixer\Config())
        ->setRules([
            // Override or add rules (e.g., enable `no_unused_imports`)
            '@Prooph' => true,
            'no_unused_imports' => true,
        ])
        ->setRiskyAllowed(true); // Enable risky fixes if needed
    
  3. Pre-Commit Hook Use tools like php-cs-fixer or husky to run checks before commits:

    composer require --dev drupol/php-cs-fixer
    

    Configure in .php-cs-fixer.dist.php or .huskyrc.

  4. Team Onboarding Document the config in your CONTRIBUTING.md:

    ## Code Style
    Run `composer cs-fix` to auto-fix style issues using Prooph’s config.
    

Workflows

  • Pair with PHPStan/Psalm: Combine static analysis with CS Fixer for a robust workflow:
    composer run cs-fix && composer run stan
    
  • Partial Fixes: Target specific files/directories:
    vendor/bin/php-cs-fixer fix src/ --config=vendor/prooph/php-cs-fixer-config/php-cs-fixer.dist.php
    

Integration Tips

  • Laravel-Specific: Exclude vendor/ and Laravel-specific files (e.g., bootstrap/cache/*) in the config:
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->in(__DIR__)
            ->exclude('vendor')
            ->exclude('bootstrap/cache')
    )
    
  • IDE Support: Configure your IDE (PHPStorm, VSCode) to use the Prooph config for real-time checks.

Gotchas and Tips

Pitfalls

  1. Rule Conflicts

    • Prooph’s config may conflict with other packages (e.g., Laravel’s no_unused_imports). Test thoroughly after merging configs.
    • Fix: Use --dry-run to preview changes before applying.
  2. Performance

    • Running CS Fixer on large codebases can be slow. Cache results with:
      vendor/bin/php-cs-fixer fix --cache=no --config=...
      
    • Tip: Use --parallel for multi-core processing (if supported by your PHP CS Fixer version).
  3. Risky Fixes

    • Some rules (e.g., concat_space) are marked as "risky" and may change logic unintentionally.
    • Tip: Review changes with --diff and disable risky rules if needed:
      ->setRiskyAllowed(false)
      
  4. Config Overrides

    • Accidentally overriding Prooph’s rules (e.g., disabling @Prooph) may break consistency.
    • Tip: Extend the config instead of replacing it:
      return (new PhpCsFixer\Config())->setRules(['@Prooph' => true, ...]);
      

Debugging

  • Unexpected Fixes: If CS Fixer modifies code unexpectedly, check the rule docs for side effects.

    • Example: ordered_imports may reorder use statements aggressively.
  • Cache Issues: Clear the cache if fixes aren’t applied:

    rm -rf ~/.cache/php-cs-fixer
    

Extension Points

  1. Custom Rules Add Prooph-specific rules by extending the config:

    ->setRules([
        '@Prooph' => true,
        'prooph_class_alignment' => true, // Hypothetical Prooph rule
    ])
    
  2. Path Aliases If using path aliases (e.g., App\app/), configure the finder:

    ->setFinder(
        PhpCsFixer\Finder::create()
            ->in(['src', 'app'])
            ->append([__DIR__.'/stubs'])
    )
    
  3. Version Pinning Pin prooph/php-cs-fixer-config to a specific version in composer.json to avoid unexpected updates:

    "require-dev": {
        "prooph/php-cs-fixer-config": "1.2.0"
    }
    
  4. Git Attributes Use .gitattributes to enforce CS Fixer on specific files:

    *.php diff=phpcsfixer
    

    Then configure Git to run CS Fixer on diffs.

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.
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
spatie/mailcoach-vapor