First let me admit that I'd my first encounter with Code Sniffer just yesterday.
I want to setup custom rules files for my ZF 1.x project. However all Zend snippets are not applicable.
Again another problem, I don't want to rediscover wheel (& I cant) so need to use existing snippets.
Question 1: Here the problem is, how do I know if there is existing snippet for the rule I want. As last option, I can always go and test each and every snippet but this obviously is not the most efficient way. Best way is to go through documentations of existing snippets but where are documentation for individual snippets?
Background for Question 2
I need few complex rules like for Doc comment block (just an example, I'm not going to implement all):
- Every class and method must have Doc comment block.
- Short description is mandatory
- Short description can have maximum 3 lines. (Each line <= 120 characters)
- If there are function parameters, @param is mandatory for every parameter.
- Error must be raised for @param which is not given as function parameter. (Developers here remove parameters but forget to remove them from doc comment block. Common issue here.)
- Long description is optional but if present, one line break needed between short and long description.
- One line break needed between description and @tags.
- No line break between @tags but @return, if present, must be at the end.
- Only @throws is allowed after @return.
- if @author present, it must be company name, not individual name.
- @version not allowed.
Obviously there are lot of custom requirements so I guess I'll never get existing snippet for that and need to write custom snippet but how? I'd gone through some snippet php files and at first glance, it seems a bit complex. Only two options, understand complete CS code, and in that case, I'll prefer manual review using phabricator, or go through documentation, which do not seems complete and helpful.
Question 2: So next question, which approach others are following to understand CS code and write their own snippet, in case needed?
PS: Before asking that question, I'd gone through all 10 pages of CS documentation given on pear.php.net and those 10 pages do not answer above two question completely.
Edit after first comment
My existing rule-set file:
<?xml version="1.0"?>
<ruleset name="eetest">
<description>Below are the standard builds based on coding standards need to follow in
BAS development.</description>
<!-- Include some specific sniffs -->
<rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"/>
<rule ref="Generic.Commenting.Todo"/>
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
<rule ref="Generic.NamingConventions.ConstructorName"/>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.PHP.DeprecatedFunctions"/>
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
<rule ref="Generic.PHP.LowerCaseKeyword"/>
<rule ref="Generic.Strings.UnnecessaryStringConcat"/>
<rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
<rule ref="Generic.WhiteSpace.ScopeIndent"/>
<rule ref="PEAR.ControlStructures.MultiLineCondition"/>
<rule ref="PEAR.Files.IncludingFile"/>
<rule ref="PEAR.Formatting.MultiLineAssignment"/>
<rule ref="Zend.Debug.CodeAnalyzer"/>
<rule ref="Zend.NamingConventions.ValidVariableName"/>
<rule ref="Zend.Files.ClosingTag"/>
<!-- Method names MUST be declared in camelCase(). -->
<rule ref="Generic.NamingConventions.CamelCapsFunctionName">
<properties>
<property name="strict" value="true"/>
</properties>
</rule>
<!-- We don't want gsjlint throwing errors for things we already check -->
<rule ref="Generic.Debug.ClosureLinter">
<properties>
<property name="errorCodes" type="array" value="0210"/>
<property name="ignoreCodes" type="array" value="0001,0110,0240"/>
</properties>
</rule>
<rule ref="Generic.Debug.ClosureLinter.ExternalToolError">
<message>%2$s</message>
</rule>
<!-- Only one argument per line in multi-line function calls -->
<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>
</ruleset>
No custom PHP code till now as I'm struggling on understanding what sippet code is doing.