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

Yii 2 Web Framework Coding Standard

This repository contains settings for Yii2 coding style for various tools.

Getting code

You can get code style definition using one of the following methods.

  • Clone yiisoft/yii2-coding-standards repository:
git clone git@github.com:yiisoft/yii2-coding-standards.git
  • Install composer.phar distribution:
curl -sS https://getcomposer.org/installer | php

Or if your system doesn't have CURL installed:

php -r "eval('?>'.file_get_contents('https://getcomposer.org/installer'));"
  • Set up all dependencies declared in composer.json:
php composer.phar install

PHP_Codesniffer

PHP_CodeSniffer coding standard, rule set and sniff token parsing classes for the Yii 2 Web Framework. Overally rules are based on PSR-12 standard with some minor exceptions and changes. Rules derived from PSR-12 standard and excluded in Yii2 standard were implemented (or planned to be) as sniff classes.

Rules could also be used for checking code style of an existing Yii2 applications.

Everything that is merged into main Yii2 development repository being checked with these rule set as well.

Using code style

After CodeSniffer is installed you can launch it with custom code style using the following syntax:

$ ./vendor/bin/phpcs --extensions=php --standard=Yii2 /home/resurtm/work/Yii2MegaApp/

Installation can be also be done automatically with this tool:

composer require --dev dealerdirect/phpcodesniffer-composer-installer

When using Composer 2.2 or higher, Composer will ask for your permission to allow this plugin to execute code. For this plugin to be functional, permission needs to be granted.

When permission has been granted, the following snippet will automatically be added to your composer.json file by Composer:

{
    "config": {
        "allow-plugins": {
            "dealerdirect/phpcodesniffer-composer-installer": true
        }
    }
}

When using Composer < 2.2, you can add the permission flag ahead of the upgrade to Composer 2.2, by running:

composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true

If you're using PhpStorm you can configure it to use CodeSniffer using Settings → PHP → Code Sniffer. Yii2 code style can be specified at Inspections → PHP → PHP Code Sniffer validation.

Useful links

PhpStorm

Yii uses PSR-12 as code style standard. You can choose these via SettingsCode StylePHPSet from...Predefined StylePSR12.

ADDITIONAL NOTES

Feel free to request additional features, submit bugs and problems.

Thank you for choosing Yii Framework!

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