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

yiisoft/code-style

Coding style and quality tools for PHP projects from Yii. Provides configuration and presets to keep code formatting consistent and enforce standards across your repository, helping teams maintain clean, readable code with automated checks.

View on GitHub
Deep Wiki
Context7

Getting Started

Start by installing yiisoft/code-style via Composer:

composer require --dev yiisoft/code-style

This package provides predefined PHP CS Fixer rule sets tailored for Yii projects. After installation, create or update your .php-cs-fixer.dist.php file to use one of its rule sets—typically Yiisoft\CodeStyle\Yiisoft::getRuleset(). Then run vendor/bin/php-cs-fixer fix to enforce consistency across your codebase. Your first use case will be automatically formatting newly written Yii controllers, models, or modules to match Yii’s internal coding standards.

Implementation Patterns

  • Centralized Configuration: Declare the rule set once in .php-cs-fixer.dist.php and reuse it across all Yii-based repositories for consistency.
  • Customization: Extend the provided ruleset to add project-specific rules:
    $config = Yiisoft\CodeStyle\Yiisoft::getRuleset();
    $config->setRules([
        'phpdoc_summary' => false,
        'no_superfluous_phpdoc_tags' => true,
    ]);
    return $config;
    
  • CI Integration: Add php-cs-fixer to your CI pipeline to fail builds if code doesn’t conform—use --dry-run for validation-only checks.
  • IDE Integration: Configure PHPStorm or VSCode to run php-cs-fixer on file save using the config file, ensuring real-time compliance.
  • Migration Aid: Run the fixer on legacy codebases to progressively bring them up to Yii’s modern style without manual refactoring.

Gotchas and Tips

  • Stale Rule Sets: The package isn’t updated in real time with PHP CS Fixer’s latest rules—check if your target version includes a needed fixer and override if necessary.
  • PHP Version Alignment: Ensure your PHP version matches the requirements of the installed yiisoft/code-style and PHP CS Fixer—mismatches cause silent failures or exceptions.
  • Yiisoft-Specific Sniffs: Some rules assume Composer structure (e.g., autoloading PSR-4 paths) or Yii-specific conventions (e.g., Component inheritance patterns)—validate results carefully in non-standard setups.
  • Override Strategy: Instead of removing entire rule sets, prefer overriding individual rules via setRules() to retain base compatibility.
  • Debugging Fixes: Use --diff --dry-run -vvv to see why a rule changed code; this helps troubleshoot unexpected fixes (e.g., docblock adjustments).
  • Future Proofing: Pin exact versions in composer.json—this package uses semver, but changes to rule sets may alter formatting drastically (e.g., between minor versions).
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
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
uri-template/tests