mayflower / mo4-coding-standard
PHP CodeSniffer ruleset implementing the MO4 coding standards extending the Symfony coding standards.
Installs: 465 471
Dependents: 6
Suggesters: 0
Security: 0
Stars: 17
Watchers: 12
Forks: 10
Open Issues: 4
Type:phpcodesniffer-standard
pkg:composer/mayflower/mo4-coding-standard
Requires
- php: ~7.2 || ~8.0
- dealerdirect/phpcodesniffer-composer-installer: ~0.7 || ~1.0
- escapestudios/symfony2-coding-standard: ^3.16.0
- slevomat/coding-standard: ^8.14
- squizlabs/php_codesniffer: ^3.8.0
Requires (Dev)
- ergebnis/composer-normalize: >=2.19 <2.30
- phan/phan: ^5.4.2
- phpstan/phpstan: ^1.12
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^7.5.20 || ^8.5.36 || ^9.6.15
- psalm/plugin-phpunit: ^0.18
- vimeo/psalm: ^4.30
- dev-master
- v10.0.2
- v10.0.1
- v10.0.0
- v9.0.1
- v9.0.0
- v8.0.1
- v8.0.0
- v7.0.0
- v6.0.0
- v5.0.0
- v4.0.0
- v3.2.2
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.1
- v3.0.0
- v2.1.4
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.0
- v1.0.0
- dev-10.x-stable
- dev-9.x-stable
- dev-8.x-stable
- dev-6.x-stable
- dev-2.x-stable
- dev-3.x-stable
- dev-4.x-stable
- dev-5.x-stable
- dev-phpcs_2.9
This package is auto-updated.
Last update: 2025-10-18 17:17:35 UTC
README
Provides a PHP CodeSniffer ruleset for the MO4 coding standard
MO4 Coding Standard
The MO4 Coding Standard is an extension of the Symfony Coding Standard and adds following rules:
MO4.Arrays.ArrayDoubleArrowAlignment
- In associative arrays, the =>operators must be aligned.
- In arrays, the key and =>operator must be on the same line.
MO4.Arrays.MultiLineArray
- 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.
MO4.Commenting.PropertyComment
- doc blocks of class properties must be multiline and have exactly one @varannotation
MO4.Formatting.AlphabeticalUseStatements
- usestatements must be sorted lexicographically. The order function can be configured.
Configuration
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 strcoll
- string-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>
MO4.Formatting.UnnecessaryNamespaceUsage
- The imported class name must be used, when it was imported with a usestatement.
MO4.Strings.VariableInDoubleQuotedString
- Interpolated variables in double quoted strings must be surrounded by { }, e.g.{$VAR}instead of$VAR.
MO4.WhiteSpace.ConstantSpacing
- const must be followed by a single space.
MO4.WhiteSpace.MultipleEmptyLines
- No more than one empty consecutive line is allowed. Taken from mediawiki/mediawiki-codesniffer.
Further rules (imported from other standards)
- 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.
Requires
Installation
Composer
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
Source
- 
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
Troubleshooting
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
Dependencies
- PHP CodeSniffer
- David Joos's Symfony Coding Standard
- Composer installer for PHP_CodeSniffer coding standards
- Slevomat Coding Standard
Contributing
See CONTRIBUTING.md for information.
License
This project is licensed under the MIT license. See the LICENSE file for details.