mayflower / mo4-coding-standard

MO4 Coding Standard Rules for Codesniffer based on Symfony Coding Standards.
MIT License
17 stars 10 forks source link
codesniffer coding-standard hacktoberfest php php-codesniffer qa symfony

MO4 CodeSniffer ruleset

Provides a PHP CodeSniffer ruleset for the MO4 coding standard

Build Status Code Coverage Scrutinizer Quality Level Codeclimate Maintainability SonarQube Maintainability

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock

MO4 Coding Standard

The MO4 Coding Standard is an extension of the Symfony Coding Standard and adds following rules:

MO4.Arrays.ArrayDoubleArrowAlignment

MO4.Arrays.MultiLineArray

MO4.Commenting.PropertyComment

MO4.Formatting.AlphabeticalUseStatements

Configuration

The order property of the MO4.Formatting.AlphabeticalUseStatements sniff defines which function is used for ordering.

Possible values for order:

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

MO4.Strings.VariableInDoubleQuotedString

MO4.WhiteSpace.ConstantSpacing

MO4.WhiteSpace.MultipleEmptyLines

Further rules (imported from other standards)

Note that with this ruleset, the following Symfony Coding Standard rules are not enforced:

Most of the issues can be auto-fixed with phpcbf.

Requires

Installation

Composer

Using Composer is the preferred way.

  1. Add the MO4 coding standard to composer.json

    composer require --dev mayflower/mo4-coding-standard
  2. Profit

    ./vendor/bin/phpcs --standard=MO4 path/to/my/file.php
  3. Optionally, you might set MO4 as default coding standard

    ./vendor/bin/phpcs --config-set default_standard MO4

Source

  1. Checkout this repository

    git clone https://github.com/mayflower/mo4-coding-standard.git
  2. Install dependencies

    composer install
  3. Check, that Symfony and MO4 are listed as coding standards

    ./vendor/bin/phpcs -i
  4. Profit

    ./vendor/bin/phpcs --standard=MO4 path/to/my/file.php
  5. 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

Contributing

See CONTRIBUTING.md for information.

License

This project is licensed under the MIT license. See the LICENSE file for details.