mayflower/mo4-coding-standard
PHP_CodeSniffer ruleset for the MO4 coding standard. Extends Symfony’s standard with extra sniffs for array formatting (alignment, multiline rules), property docblocks (@var), and lexicographically sorted use statements (configurable ordering).
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:
=> operators must be aligned.=> operator must be on the same line.@var annotationuse statements must be sorted lexicographically. The order function can be configured.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 character
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
string: binary safe string comparison using strcmp
use 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-insensitive: binary safe case-insensitive string comparison strcasecmp
use Examples;
use ExampleSub;
To change the sorting order for your project, add this snippet to your custom ruleset.xml:
<rule ref="MO4.Formatting.AlphabeticalUseStatements">
<properties>
<property name="order" value="string-locale"/>
</properties>
</rule>
use statement.{ }, e.g. {$VAR} instead of $VAR.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 valuethe license block has to be present at the top of every PHP file, before the namespace": the license block can be omittedMost of the issues can be auto-fixed with phpcbf.
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
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
See CONTRIBUTING.md for information.
This project is licensed under the MIT license. See the LICENSE file for details.
How can I help you explore Laravel packages today?