Provides a PHP CodeSniffer ruleset for the MO4 coding standard
The MO4 Coding Standard is an extension of the Symfony Coding Standard and adds following rules:
- short array syntax
[...]
must be used instead ofarray(...)
- in multi line arrays, the opening bracket must be followed by newline
- in multi line arrays, the closing bracket must be in own line
- in multi line arrays, the elements must be indented
- in associative arrays, the
=>
operators must be aligned - in arrays, the key and
=>
operator must be on the same line - each consecutive variable assignment must align at the assignment operator
- use statements must be sorted lexicographically, grouped by empty lines. The order function can be configured.
- you should use the imported class name when it was imported with a use statement
- interpolated variables in double quoted strings must be surrounded by
{ }
, e.g.{$VAR}
instead of$VAR
sprintf
or"{$VAR1} {$VAR2}"
must be used instead of the dot operator; concat operators are only allowed to concatenate constants and multi line strings- a whitespace is required after each typecast, e.g.
(int) $value
instead of(int)$value
- doc blocks of class properties must be multiline and have exactly one
@var
annotation - Multiline conditions must follow the respective PEAR standard
- There must be at least one space around operators, and (except for aligning multiline statements) at most one, see the
respective Squizlabs Sniff
we imported with
ignoreNewlines = false
The order
property of the MO4.Formatting.AlphabeticalUseStatements
sniff defines
which function is used for ordering.
Possible values for order:
dictionary
(default): based on strcmp, the namespace separator precedes any other characteruse Doctrine\ORM\Query; use Doctrine\ORM\Query\Expr; use Doctrine\ORM\QueryBuilder;
string
: binary safe string comparison using strcmpuse Doctrine\ORM\Query; use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\Query\Expr; use ExampleSub; use Examples;
string-locale
: locale based string comparison using strcollstring-case-insenstive
: binary safe case-insensitive string comparison strcasecmpuse Examples; use ExampleSub;
<rule ref="MO4.Formatting.AlphabeticalUseStatements">
<properties>
<property name="order" value="string-locale"/>
</properties>
</rule>
Using Composer is the preferred way.
-
Add the MO4 coding standard to
composer.json
composer require --dev mayflower/mo4-coding-standard
-
Profit
./vendor/bin/phpcs --standard=MO4 path/to/my/file.php
-
Optionally, you might set MO4 as default coding standard
./vendor/bin/phpcs --config-set default_standard MO4
-
Checkout this repository
git clone https://github.com/mayflower/mo4-coding-standard.git
-
Install dependencies
composer install
-
Check, that Symfony and MO4 are listed as coding standards
./vendor/bin/phpcs -i
-
Profit
./vendor/bin/phpcs --standard=MO4 path/to/my/file.php
-
Optionally, you might set MO4 as default coding standard
./vendor/bin/phpcs --config-set default_standard MO4
-
Install phpcs
pear install PHP_CodeSniffer
-
Check out the Symfony coding standard and this repository
git clone https://github.com/djoos/symfony-coding-standard.git git clone https://github.com/mayflower/mo4-coding-standard.git
-
Select the MO4 ruleset as your default coding standard
phpcs --config-set installed_paths PATH/TO/symfony2-coding-standard,PATH/TO/mo4-coding-standard phpcs --config-set default_standard MO4
-
Profit
phpcs --standard=MO4 path/to/my/file.php
-
Optionally, you might set MO4 as default coding standard
phpcs --config-set default_standard MO4
See CONTRIBUTING.md for information.
This project is licensed under the MIT license.