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

spiral/code-style

PER-2–based PHP CS Fixer ruleset for Spiral components. Install as a dev dependency, add a .php-cs-fixer.dist.php via the Builder to include project paths, run via composer scripts, and integrate checks or auto-fixes in GitHub Actions CI.

View on GitHub
Deep Wiki
Context7

Getting Started

Install spiral/code-style as a dev dependency. Create a .php-cs-fixer.dist.php file in your project root using the provided Builder API to define paths—typically src/ and the config file itself. Run php-cs-fixer fix (via Composer scripts or directly) to apply fixes, or --dry-run to check style without modifying files.

composer require --dev spiral/code-style

# Create .php-cs-fixer.dist.php (see below)
php-cs-fixer fix --dry-run
<?php declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
return \Spiral\CodeStyle\Builder::create()
    ->include(__DIR__ . '/src')
    ->include(__FILE__)
    ->build();

Implementation Patterns

  • Standard Composer scripts: Add "cs:diff" and "cs:fix" to composer.json for local style checks and fixes.
  • CI integration: Embed the prebuilt GitHub Actions workflows (cs.yml, cs-fix.yml) for automated enforcement in PRs/Merge requests.
  • Composer-driven workflows: Use scripts and GitHub Actions to enforce style before merge (via cs:diff) and auto-correct on demand (via cs:fix).
  • Extension: Override or extend rules in the config file by chaining ->useRule(...) or ->exclude(...) after Builder::create()—e.g., .exclude('config/*.php') or ->useRule('nullable_type_declaration_for_default_null_value' => true).

Gotchas and Tips

  • PHP CS Fixer versioning: spiral/code-style uses php-cs-fixer/shim (v2.3.0+), so avoid mixing with standalone php-cs-fixer installs—conflicting PHAR versions cause silent inconsistencies.
  • Default excludes: Per v2.2.2+, use ->exclude() (not manual ->notName()), but ensure paths are relative to the project root__DIR__ expansions in builders can cause path mismatches if misaligned.
  • PER-2 alignment: The ruleset is strict on Spiral conventions (e.g., @method in docblocks, no trailing commas in arrays, no spaces in $arr[ $i ]$arr[$i]). Adjust only if absolutely necessary—deviations cause CI failures across teams.
  • Deprecated config usage: v2.3.1 fixed PHP 8.4 deprecations in closures and nullable types—update even if using Laravel if you see ReturnTypeWillChange-like notices or PHP 8.4+ in CI.
  • Non-breaking only: This package does not enforce PSR-12 fully (e.g.,Per-2 allows single-line docblocks); use --diff to audit changes before committing.
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
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
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