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

phlak/coding-standards

Predefined PHP-CS-Fixer coding standards by PHLAK. Install as a dev dependency, initialize via composer exec cs init or create a config using ConfigFactory with a Finder, then run php-cs-fixer. Supports adding or overriding rules via ConfigFactory::make().

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package as a dev dependency and initialize the config with the built-in CLI tool — no manual file editing needed.

  1. Run: composer require --dev phlak/coding-standards
    • Requires PHP 8.2+ — confirm your environment matches this minimum.
  2. Initialize config: composer exec cs init
    • This generates .php-cs-fixer.dist.php with sensible defaults for Laravel projects.
  3. Run fixes: ./vendor/bin/php-cs-fixer fix src tests
    • Add to composer.json scripts for routine use (e.g., "cs:fix": "php-cs-fixer fix").

Implementation Patterns

  • Leverage ConfigFactory::make() for dynamic config — use it in .php-cs-fixer.dist.php instead of static arrays.
    return PHLAK\CodingStandards\ConfigFactory::make($finder)
        ->setIndent("\t") // Laravel uses tabs; tweak if needed
        ->setRiskyAllowed(); // Enable for modern PHP upgrades (e.g., PHP 8.3+ features)
    
  • Override rules selectively via merge — append project-specific rules as the second argument.
    ConfigFactory::make($finder, [
        'phpdoc_summary' => false, // Disable_summary formatting (e.g., for Doctrine annotations)
        'global_namespace_import' => ['import_classes' => true],
    ]);
    
  • Integrate with Laravel’s test suite — run fixes in CI before test runs:
    # .github/workflows/ci.yaml
    - name: Fix coding standards
      run: composer cs:fix
    - name: Check standards (CI guard)
      run: ./vendor/bin/php-cs-fixer fix --dry-run
    

Gotchas and Tips

  • PHP 8.2+ mandatory — no fallback for legacy projects; avoid if stuck on PHP 8.0/8.1.
  • Factory overrides config files.php-cs-fixer.dist.php created by cs init is replaced by ConfigFactory::make() logic — don’t mix static config definitions.
  • Rule overrides replace entire options — passing 'ordered_imports' => [...] replaces the default config, not merges it. Use ConfigFactory::make()->getRules() to fetch defaults first if partial customization is needed.
  • Cache issues cause inconsistent results — clear manually if rules change:
    ./vendor/bin/php-cs-fixer fix --clear-cache
  • Low adoption (0 dependents) — tread carefully in critical pipelines; test upgrades thoroughly. Check GitHub Discussions for niche edge cases.
  • Laravel-specific tip — disable Laravel’s no_unused_imports override if using ConfigFactory, as this package already enforces import ordering — conflicts otherwise cause noisy 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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle