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

amphp/php-cs-fixer-config

Shared PHP-CS-Fixer configuration used across amphp projects. Install as a dev dependency, create a .php_cs.dist that returns Amp\CodeStyle\Config, configure the Finder paths and cache file, and run php-cs-fixer locally or in CI (e.g., Travis) for consistent styling.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing the package as a dev dependency:

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

Then create a .php_cs.dist file in your project root (as shown in the README) using Amp\CodeStyle\Config. Configure the file finder to target src, test, and examples, set a cache file (e.g., .php_cs.cache), and return the config. This is the minimal setup needed to begin enforcing AMP’s consistent coding standards across your project.

Implementation Patterns

  • Centralized styling: Use this package as the single source of truth for code style across multiple PHP packages (especially if part of the Amp ecosystem or similar async PHP projects).
  • CI integration: Integrate with CI via --dry-run in script blocks (e.g., Travis, GitHub Actions), caching .php_cs.cache to speed up runs. Use --verbose --diff for informative failures.
  • Pre-commit hooks: Add a lightweight pre-commit hook (as provided in the README) to auto-fix staged PHP files only if php-cs-fixer is installed—ideal for avoiding breakage when contributors lack the tool.
  • Local development: Run ./vendor/bin/php-cs-fixer fix -v before committing to ensure conformity. IDE integration (e.g., PHPStorm or VSCode integrations) can also leverage .php_cs.dist automatically.

Gotchas and Tips

  • Strict types enforcement: v2+ includes declare(strict_types=1) by default—ensure all files are compatible with strict types; partially compatible files may break after auto-fix.
  • Cache conflicts: If CI and local dev use different cache paths, ensure TRAVIS or equivalent env vars are handled—or better, use project-local caching (__DIR__ . '/.php_cs.cache') to avoid cross-run contamination.
  • Pre-commit caveats: The shipped hook uses grep -e '^[AM]…', which only processes added/modified files at commit time; it won’t catch unstaged changes or changes to existing untracked files. Consider adding git stash support or switching to git diff --cached for broader safety.
  • Version locking: Though the package depends on friendsofphp/php-cs-fixer:^3.5, rule sets evolve—even patch versions (e.g., v2.1.1 fixing str_increment) may change formatting. Pin to exact versions in CI if reproducibility is critical.
  • Extensibility: Extend Amp\CodeStyle\Config to override/add rules (e.g., ->setRiskyAllowed(true) for risky rules, or .include additional configs), but avoid diverging significantly—use consistency over customization.
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4
php-http/client-implementation
phpcr/phpcr-implementation
cucumber/gherkin-monorepo
haydenpierce/class-finder
psr/simple-cache-implementation