You are browsing a version that is no longer maintained. |
Customizing to your needs
While Doctrine Coding Standard is based on PSR-2, it also consists of a lot of additional advanced and opinionated rules and checks, mostly imported from the Slevomat Coding Standard.
As different people and projects have different tastes, sooner or later you may find some of them not compatible with your needs.
Fortunately that's not a problem and it's straightforward to customize the standard to fit your needs, either by reconfiguring the rules or by disabling/replacing them entirely.
Configurable vs. tailored rules
Some rules have configurable properties to adjust their behavior (i.e. return type colon spacing), other are made for one specific purpose (i.e. require or forbid yoda conditions).
To find out whether the specific rule is configurable, take a look at CodeSniffer's documentation and Slevomat CS documentation.
Configuring rule properties
When a sniff is configurable, you can adjust its behavior by setting its properties:
1 <rule ref="Doctrine"/>
<rule ref="Generic.Files.LineLength">
<properties>
<!-- set soft line length limit to 120 characters -->
<property name="lineLimit" value="120"/>
<!-- set hard line length limit to 160 characters -->
<property name="absoluteLineLimit" value="160"/>
</properties>
</rule>
2
3
4
5
6
7
8
9
10
Excluding offending rules
It's possible to exclude a specific rule:
For better granularity, it's possible to also exclude only specific errors (if the sniff reports multiple errors):
It's also possible to exclude either a rule or an error for specific files/directories:
Adding new rules
Adding new rules is simple, all you need to do is add a new <rule>
block:
You can directly pick any sniffs from either CodeSniffer itself or Slevomat CS.