calbrecht / mo4-coding-standard

MO4 Coding Standard Rules for Codesniffer based on Symfony Coding Standards.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MO4 CodeSniffer ruleset

Provides a PHP CodeSniffer ruleset for the MO4 coding standard

Build Status Build Status Scrutinizer Quality Level

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

Requires

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 of array(...)
  • 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

Configuration

MO4.Formatting.AlphabeticalUseStatements

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-insenstive: binary safe case-insensitive string comparison strcasecmp
    use Examples;
    use ExampleSub;
<rule ref="MO4.Formatting.AlphabeticalUseStatements">
    <properties>
        <property name="order" value="string-locale"/>
    </properties>
</rule>

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
    

Pear

  1. Install phpcs

     pear install PHP_CodeSniffer
    
  2. 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
    
  3. 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
    
  4. Profit

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

     phpcs --config-set default_standard MO4
    

Contributing

See CONTRIBUTING.md for information.

Credit

License

This project is licensed under the MIT license.

About

MO4 Coding Standard Rules for Codesniffer based on Symfony Coding Standards.

License:MIT License


Languages

Language:PHP 100.0%