Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

mayflower/mo4-coding-standard

Repository files navigation

Provides a PHP CodeSniffer ruleset for the MO4 coding standard

Build StatusCode CoverageCodeclimate MaintainabilitySonarQube Maintainability

Latest Stable VersionTotal DownloadsLatest Unstable VersionLicensecomposer.lock

MO4 Coding Standard

The MO4 Coding Standard is an extension of theSymfony 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@var annotation

MO4.Formatting.AlphabeticalUseStatements

  • use statements must be sorted lexicographically. The order function can be configured.

Configuration

Theorder property of theMO4.Formatting.AlphabeticalUseStatements sniff defineswhich function is used for ordering.

Possible values for order:

  • dictionary (default): based onstrcmp, the namespace separatorprecedes any other character
    useDoctrine\ORM\Query;useDoctrine\ORM\Query\Expr;useDoctrine\ORM\QueryBuilder;
  • string: binary safe string comparison usingstrcmp
    useDoctrine\ORM\Query;useDoctrine\ORM\QueryBuilder;useDoctrine\ORM\Query\Expr;useExampleSub;useExamples;
  • string-locale: locale based string comparison usingstrcoll
  • string-case-insensitive: binary safe case-insensitive string comparisonstrcasecmp
    useExamples;useExampleSub;

To change the sorting order for your project, add this snippet to your customruleset.xml:

<ruleref="MO4.Formatting.AlphabeticalUseStatements">    <properties>        <propertyname="order"value="string-locale"/>    </properties></rule>

MO4.Formatting.UnnecessaryNamespaceUsage

  • The imported class name must be used, when it was imported with ause statement.

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

Further rules (imported from other standards)

  • SeeMO4/ruleset.xml, which has each imported rule commented.

Note that with this ruleset, the followingSymfony 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 withphpcbf.

Requires

Installation

Composer

UsingComposer is the preferred way.

  1. Add the MO4 coding standard tocomposer.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

Ifphpcs complains that MO4 is not installed, please check the installed coding standards withphpcs -i and thatinstalled_paths is set correctly withphpcs --config-show

Dependencies

Contributing

SeeCONTRIBUTING.md for information.

License

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors10

Languages


[8]ページ先頭

©2009-2025 Movatter.jp