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
Yii2 Coding Standards

Yii2 Coding Standards Laravel Package

yiisoft/yii2-coding-standards

Yii 2 coding standards package providing PHP_CodeSniffer ruleset, sniffs, and tooling configs based on PSR-12 with Yii2-specific tweaks. Use it to enforce Yii2 core style in framework development or in existing Yii2 applications.

View on GitHub
Deep Wiki
Context7

yiisoft/yii2-coding-standards provides the official Yii2 coding style configuration for PHP_CodeSniffer, aligning largely with PSR-12 while applying Yii-specific exceptions and additions. It’s the same ruleset used to validate code merged into the main Yii 2 Web Framework repository.

Use it to enforce consistent formatting in Yii2 apps and libraries via phpcs with the Yii2 standard.

  • PHPCS ruleset tailored for Yii2 (PSR-12 based with tweaks)
  • Includes sniffs and token parsing helpers for Yii-specific rules
  • Works for both framework development and existing Yii2 projects
  • Easy integration via Composer and phpcs CLI
  • Supports auto-install with dealerdirect/phpcodesniffer-composer-installer
Frequently asked questions about Yii2 Coding Standards
Can I use yiisoft/yii2-coding-standards in a Laravel project?
Yes, but with caveats. The package enforces Yii2-specific rules (e.g., array syntax, naming conventions) that may conflict with Laravel’s PSR-12 standards. Use it for legacy Yii2 codebases or hybrid projects, then override conflicting rules in your `.phpcs.xml` config. Example: Disable `yiisoft.array-syntax` if your Laravel app uses `[]` instead of `array()`.
How do I install this package in a Laravel project?
Run `composer require --dev yiisoft/yii2-coding-standards` and configure PHP_CodeSniffer to use the Yii2 standard. Add this to your `.phpcs.xml`: `<rule ref="yiisoft"/>` and `<config name="installedPackages" value="yiisoft/yii2-coding-standards"/>`. For auto-installation, use `dealerdirect/phpcodesniffer-composer-installer` via Composer’s `allow-plugins` config.
Will this break Laravel’s existing PSR-12 compliance?
Potentially. Yii2 rules may flag Laravel idioms (e.g., facades like `Route::get()`) as violations. Audit your codebase first, then selectively disable conflicting rules. For example, exclude Blade templates or override `yiisoft.naming-conventions` for Laravel models. Test in CI before enforcing globally.
Does this package support Laravel’s latest versions (10.x/11.x)?
The package itself is framework-agnostic and works with any PHP_CodeSniffer-compatible project. However, Yii2-specific rules (e.g., `Yii::$app` usage) won’t apply to Laravel. Use it for cross-framework consistency or legacy code, but avoid enforcing Yii2 rules on pure Laravel components. Version compatibility depends on PHP_CodeSniffer (v3+).
How do I integrate this into Laravel’s CI/CD pipeline?
Add a GitHub Actions/GitLab CI step to run PHP_CodeSniffer with the Yii2 standard. Example: `vendor/bin/phpcs --standard=yiisoft src/ --ignore=tests,resources`. Use `--warning-severity` to start with warnings before failing builds. For hybrid projects, apply rules only to `/legacy/` directories or specific file patterns.
Are there alternatives for enforcing Yii2-style rules in Laravel?
For pure Laravel projects, stick to `php-cs-fixer` (with PSR-12 rules) or `laravel-pint`. If you need Yii2-specific rules, fork this package and customize it, or use `phpcs` with a custom `.phpcs.xml` that combines PSR-12 and Yii2 rules. Avoid mixing frameworks unless necessary—consider gradual migration instead.
How do I handle false positives for Laravel-specific code (e.g., facades, Blade)?
Exclude Laravel-specific files/directories using `--ignore` flags or configure PHP_CodeSniffer to skip them. Example: `<exclude-pattern>*.blade.php</exclude-pattern>` in `.phpcs.xml`. For facades, override rules like `yiisoft.StaticAnalysis` to allow `Route::get()` calls. Document these exceptions in your team’s coding guidelines.
Can I use this package for testing Yii2 libraries alongside Laravel?
Yes, this is a common use case. Apply the Yii2 standard only to the Yii2 library directory (e.g., `/vendor/yiisoft/yi2` or `/packages/yi2-library`). Use `--paths` to target specific folders: `phpcs --standard=yiisoft /path/to/yi2-library`. This avoids polluting your Laravel codebase with Yii2 rules.
What PHP_CodeSniffer version does this package require?
The package requires PHP_CodeSniffer **version 3.0 or higher**. Laravel projects typically use SquizLabs’ PHP_CodeSniffer (v3+), so no additional dependencies are needed. Verify compatibility by running `vendor/bin/phpcs --version` after installation. If using Composer 2.2+, ensure `dealerdirect/phpcodesniffer-composer-installer` is allowed in `allow-plugins`.
How do I customize or extend the Yii2 ruleset for Laravel?
Fork the repository and modify the sniffs in `/sniffs/`. For example, override `yiisoft.ArraySyntaxSniff` to allow Laravel’s `[]` syntax. Alternatively, extend the ruleset in `.phpcs.xml` using `<rule ref="yiisoft.ArraySyntax">` with custom parameters. Test changes with `phpcs --test` to avoid breaking existing Yii2 compliance.
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