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:
- In associative arrays, the
=>operators must be aligned. - In arrays, the key and
=>operator must be on the same line.
- 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.
- doc blocks of class properties must be multiline and have exactly one
@varannotation
- The imported class name must be used, when it was imported with a
usestatement.
- Interpolated variables in double quoted strings must be surrounded by
{ }, e.g.{$VAR}instead of$VAR.
- const must be followed by a single space.
- No more than one empty consecutive line is allowed. Taken from mediawiki/mediawiki-codesniffer.
- See
MO4/ruleset.xml, which has each imported rule commented.
Note that with this ruleset, the following Symfony Coding Standard rules are not enforced:
- "
add doc blocks for all classes": the doc block for classes can be omitted, if they add no value - "
the license block has to be present at the top of every PHP file, before the namespace": the license block can be omitted
Most of the issues can be auto-fixed with phpcbf.
Using Composer is the preferred way.
-
Add the MO4 coding standard to
composer.jsoncomposer 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
If phpcs complains that MO4 is not installed, please check the installed coding standards with
phpcs -i and that installed_paths is set correctly with phpcs --config-show
- PHP CodeSniffer
- David Joos's Symfony Coding Standard
- Composer installer for PHP_CodeSniffer coding standards
- Slevomat Coding Standard
See CONTRIBUTING.md for information.
This project is licensed under the MIT license. See the LICENSE file for details.