Add phpcs rules
This commit is contained in:
parent
5ce2c01505
commit
fb37f748d4
|
@ -1,5 +1,7 @@
|
|||
* Quality Assurance Settings for museum-digital
|
||||
|
||||
Most of the code used at [museum-digital](https://www.museum-digital.org) is written in PHP. To keep a uniform code style throughout the code, we use [PHP Code Sniffer](https://github.com/squizlabs/PHP_CodeSniffer).
|
||||
|
||||
** Tools used
|
||||
|
||||
- [[https://github.com/squizlabs/PHP_CodeSniffer][php-codesniffer]]
|
||||
|
@ -9,3 +11,5 @@
|
|||
** This Repository
|
||||
|
||||
This repository serves to collect generally applicable rules, that can be embedded into the specific rule sets of the different projects.
|
||||
|
||||
The file `md_phpcs_rules.xml` contains the main style guide. When rewriting files to fit the uniform style rules, `md_phpcs_rules_basic.xml` comes in handy as a first step. It contains the same rules, excluding some which require or encourage a more in-depth look at the code (the prohibition of procedural-style calls to mysqli functions is e.g. a good opportunity to check the efficiency of queries).
|
||||
|
|
221
rules/md_phpcs_rules.xml
Normal file
221
rules/md_phpcs_rules.xml
Normal file
|
@ -0,0 +1,221 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="museumdigital">
|
||||
<description>Coding standard for museum-digital.
|
||||
Based on Zend with some additions.</description>
|
||||
|
||||
<!-- Handle commenting -->
|
||||
<!-- <rule ref='Generic.Commenting'/> -->
|
||||
<rule ref='PEAR.Commenting.FunctionComment'/>
|
||||
|
||||
<!-- <rule ref='Generic.Commenting.DocComment' /> -->
|
||||
<rule ref='Squiz.Commenting.DocCommentAlignment'/>
|
||||
<rule ref='Squiz.Commenting.FunctionComment'/>
|
||||
<rule ref='Squiz.Commenting.ClassComment'/>
|
||||
|
||||
<!--
|
||||
<rule ref='PEAR.ControlStructures.ControlSignature'>
|
||||
<properties>
|
||||
<property name="spacing" value="5" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
<rule ref='PEAR.ControlStructures.MultiLineCondition'/>
|
||||
<rule ref='Squiz.ControlStructures.ElseIfDeclaration'/>
|
||||
<rule ref='Squiz.ControlStructures.ForEachLoopDeclaration'/>
|
||||
<rule ref='Squiz.ControlStructures.ForLoopDeclaration'/>
|
||||
<!--
|
||||
Warn about lines longer than 100 chars,
|
||||
and error for lines longer than 135 chars.
|
||||
-> This is currently disabled, as HTML lines easily go beyond any reasonable limits if they include links.
|
||||
<rule ref="Generic.Files.LineLength">
|
||||
<properties>
|
||||
<property name="lineLimit" value="130" />
|
||||
<property name="absoluteLineLimit" value="140" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Don't check function braces, but check closure braces. -->
|
||||
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
|
||||
<properties>
|
||||
<property name="checkFunctions" value="false" />
|
||||
<property name="checkClosures" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<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.CodeAnalysis.UnconditionalIfStatement'/>
|
||||
<rule ref='Generic.CodeAnalysis.UnusedFunctionParameter'/>
|
||||
|
||||
<rule ref='PEAR.Files'/>
|
||||
|
||||
<rule ref='PEAR.Formatting'/>
|
||||
|
||||
<rule ref='Generic.Functions.OpeningFunctionBraceKernighanRitchie'/>
|
||||
<rule ref='Generic.Functions.FunctionCallArgumentSpacing'/>
|
||||
<!--
|
||||
<rule ref='PEAR.Functions.FunctionCallSignature'/>
|
||||
<rule ref='PEAR.Functions.FunctionDeclaration'/>
|
||||
-->
|
||||
<rule ref='Squiz.Functions.FunctionDeclaration'/>
|
||||
<rule ref='PEAR.Functions.ValidDefaultValue'/>
|
||||
|
||||
<rule ref='PEAR.NamingConventions.ValidClassName'/>
|
||||
|
||||
<!--
|
||||
Have code block comments look like // end foreach() etc.
|
||||
<rule ref="Squiz.Commenting.LongConditionClosingComment">
|
||||
<properties>
|
||||
<property name="commentFormat" value="// end" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
|
||||
<properties>
|
||||
<property name="equalsSpacing" value="1" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref='Zend.Files.ClosingTag'/>
|
||||
<!--
|
||||
<rule ref='PEAR.NamingConventions.ValidFunctionName'/>
|
||||
<rule ref='Zend.NamingConventions.ValidVariableName' />
|
||||
We may enforce these at some point in time. We don't at the moment.
|
||||
<rule ref="Generic.Metrics.CyclomaticComplexity">
|
||||
<properties>
|
||||
<property name="complexity" value="24" />
|
||||
<property name="absoluteComplexity" value="36" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Metrics.NestingLevel">
|
||||
<properties>
|
||||
<property name="nestingLevel" value="24" />
|
||||
<property name="absoluteNestingLevel" value="30" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
<rule ref='PEAR.NamingConventions.ValidVariableName' />
|
||||
|
||||
<rule ref='Generic.PHP.DeprecatedFunctions' />
|
||||
<rule ref='Generic.PHP.CharacterBeforePHPOpeningTag' />
|
||||
<rule ref='Generic.PHP.DisallowShortOpenTag' />
|
||||
<!--
|
||||
<rule ref='Generic.Classes.OpeningBraceSameLine' />
|
||||
-->
|
||||
<rule ref='Generic.PHP.NoSilencedErrors' />
|
||||
<rule ref='Generic.PHP.SAPIUsage' />
|
||||
<rule ref='Generic.PHP.Syntax' />
|
||||
<rule ref='Generic.Arrays.DisallowLongArraySyntax' />
|
||||
<rule ref='Generic.Files.LineEndings' />
|
||||
<!--<rule ref='Generic.Files.InlineHTML' />-->
|
||||
<rule ref='Generic.Functions.OpeningFunctionBraceKernighanRitchie' />
|
||||
|
||||
<!--
|
||||
Forbidden functinos.
|
||||
Using this sniff, it is established that count is preferred over sizeof() etc.
|
||||
Notably, we use the OOP style for mysqli function calls.
|
||||
-->
|
||||
<rule ref="Generic.PHP.ForbiddenFunctions">
|
||||
<properties>
|
||||
<!-- Starting phpcs 3.3 we should use this
|
||||
<property name="forbiddenFunctions" type="array">
|
||||
<element key="delete" value="unset"/>
|
||||
<element key="print" value="echo"/>
|
||||
<element key="create_function" value="null"/>
|
||||
<element key="system" value="null"/>
|
||||
<element key="sizeof" value="count"/>
|
||||
</property>
|
||||
-->
|
||||
<property name="forbiddenFunctions" type="array" value="delete=>unset,print=>echo,create_function=>null,system=>null,sizeof=>count,mysql_query=>mysqli_query,mysqli_query=>null,mysql_num_rows=>mysqli_num_rows,mysqli_num_rows=>null,mysql_error=>mysqli_error,mysqli_stmt_init=>null,mysqli_stmt_close=>null,mysqli_real_escape_string=>null,mysqli_fetch_array=>mysqli_fetch_assoc,mysqli_fetch_assoc=>null,session_id=>null,print_r=>null,var_dump=>null" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Internal.NoCodeFound">
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
<rule ref="Squiz.PHP.DiscouragedFunctions">
|
||||
<properties>
|
||||
<property name="error" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<rule ref='Squiz.PHP.DisallowSizeFunctionsInLoops'/>
|
||||
|
||||
<rule ref='Squiz.Strings.EchoedStrings'/>
|
||||
|
||||
<rule ref="Squiz.Strings.ConcatenationSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="1" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref='PEAR.WhiteSpace'/>
|
||||
<rule ref='Generic.WhiteSpace.DisallowTabIndent'/>
|
||||
|
||||
<rule ref="Generic.Strings.UnnecessaryStringConcat">
|
||||
<properties>
|
||||
<property name="allowMultiline" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
|
||||
<properties>
|
||||
<property name="ignoreNewlines" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
|
||||
<properties>
|
||||
<!-- <property name="ignoreBlankLines" value="true" /> -->
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Ensure 1 blank line before and after functions, except at the top and bottom. -->
|
||||
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="1" />
|
||||
<property name="spacingBeforeFirst" value="0" />
|
||||
<property name="spacingAfterLast" value="0" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref='Squiz.WhiteSpace.SemicolonSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.ScopeKeywordSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.ScopeClosingBrace'/>
|
||||
<rule ref='Squiz.WhiteSpace.CastSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.FunctionClosingBraceSpace'/>
|
||||
|
||||
<rule ref='Squiz.PHP.Eval'/>
|
||||
<rule ref='Squiz.PHP.DisallowBooleanStatement'/>
|
||||
<rule ref='Squiz.Arrays.ArrayBracketSpacing'/>
|
||||
<!--
|
||||
<rule ref='Squiz.Operators.ComparisonOperatorUsage'/>
|
||||
CSS
|
||||
-->
|
||||
|
||||
<!-- Include some CSS rules I want to enforce
|
||||
-->
|
||||
<rule ref='Squiz.CSS.DuplicateStyleDefinition'/>
|
||||
<rule ref='Squiz.CSS.ClassDefinitionNameSpacing'/>
|
||||
<rule ref='Squiz.CSS.ColonSpacing'/>
|
||||
<rule ref='Squiz.CSS.EmptyClassDefinition'/>
|
||||
<!-- <rule ref='Squiz.CSS.ColourDefinition'/> -->
|
||||
<rule ref='Squiz.CSS.SemicolonSpacing'/>
|
||||
|
||||
<!--
|
||||
Javascript
|
||||
-->
|
||||
<rule ref='Generic.Debug.JSHint'/>
|
||||
<rule ref='Squiz.Debug.JSLint'/>
|
||||
|
||||
</ruleset>
|
223
rules/md_phpcs_rules_basic.xml
Normal file
223
rules/md_phpcs_rules_basic.xml
Normal file
|
@ -0,0 +1,223 @@
|
|||
<?xml version="1.0"?>
|
||||
<ruleset name="museumdigital">
|
||||
<description>Coding standard for museum-digital.
|
||||
Based on Zend with some additions.</description>
|
||||
|
||||
<!-- Include most of PEAR standard -->
|
||||
<rule ref='Generic.Commenting'/>
|
||||
<rule ref='PEAR.Commenting.FunctionComment'/>
|
||||
|
||||
<rule ref='Squiz.Commenting.DocCommentAlignment'/>
|
||||
<rule ref='Squiz.Commenting.FunctionComment'/>
|
||||
<!-- <rule ref='Squiz.Commenting.ClassComment'/>-->
|
||||
<!--
|
||||
-->
|
||||
|
||||
<!--
|
||||
<rule ref='PEAR.ControlStructures.ControlSignature'>
|
||||
<properties>
|
||||
<property name="spacing" value="5" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
<rule ref='PEAR.ControlStructures.MultiLineCondition'/>
|
||||
<rule ref='Squiz.ControlStructures.ElseIfDeclaration'/>
|
||||
<rule ref='Squiz.ControlStructures.ForEachLoopDeclaration'/>
|
||||
<rule ref='Squiz.ControlStructures.ForLoopDeclaration'/>
|
||||
<!--
|
||||
Warns if there are inline control structures. E.g. if (true == false) echo "HI";
|
||||
<rule ref="Generic.ControlStructures.InlineControlStructure">
|
||||
<properties>
|
||||
<property name="error" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
<!--
|
||||
Warn about lines longer than 100 chars,
|
||||
and error for lines longer than 135 chars.
|
||||
<rule ref="Generic.Files.LineLength">
|
||||
<properties>
|
||||
<property name="lineLimit" value="130" />
|
||||
<property name="absoluteLineLimit" value="140" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Don't check function braces, but check closure braces. -->
|
||||
<rule ref="Generic.Functions.OpeningFunctionBraceKernighanRitchie">
|
||||
<properties>
|
||||
<property name="checkFunctions" value="false" />
|
||||
<property name="checkClosures" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<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.CodeAnalysis.UnconditionalIfStatement'/>
|
||||
<rule ref='Generic.CodeAnalysis.UnusedFunctionParameter'/>
|
||||
|
||||
<rule ref='PEAR.Files'/>
|
||||
|
||||
<rule ref='PEAR.Formatting'/>
|
||||
|
||||
<rule ref='Generic.Functions.OpeningFunctionBraceKernighanRitchie'/>
|
||||
<rule ref='Generic.Functions.FunctionCallArgumentSpacing'/>
|
||||
<!--
|
||||
<rule ref='PEAR.Functions.FunctionCallSignature'/>
|
||||
<rule ref='PEAR.Functions.FunctionDeclaration'/>
|
||||
-->
|
||||
<rule ref='Squiz.Functions.FunctionDeclaration'/>
|
||||
<rule ref='PEAR.Functions.ValidDefaultValue'/>
|
||||
|
||||
<rule ref='PEAR.NamingConventions.ValidClassName'/>
|
||||
|
||||
<!-- Have code block comments look like // end foreach() etc.
|
||||
<rule ref="Squiz.Commenting.LongConditionClosingComment">
|
||||
<properties>
|
||||
<property name="lineLimit" value="40" />
|
||||
<property name="commentFormat" value="// end" />
|
||||
</properties>
|
||||
</rule> -->
|
||||
|
||||
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
|
||||
<properties>
|
||||
<property name="equalsSpacing" value="1" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref='Zend.Files.ClosingTag'/>
|
||||
<!--
|
||||
<rule ref='Zend.NamingConventions.ValidVariableName' />
|
||||
<rule ref='PEAR.NamingConventions.ValidFunctionName'/>
|
||||
We may enforce these at some point in time. We don't atm.
|
||||
<rule ref="Generic.Metrics.CyclomaticComplexity">
|
||||
<properties>
|
||||
<property name="complexity" value="24" />
|
||||
<property name="absoluteComplexity" value="36" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Generic.Metrics.NestingLevel">
|
||||
<properties>
|
||||
<property name="nestingLevel" value="24" />
|
||||
<property name="absoluteNestingLevel" value="30" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
<rule ref='PEAR.NamingConventions.ValidVariableName'/>
|
||||
|
||||
<rule ref='Generic.PHP.DeprecatedFunctions'/>
|
||||
<rule ref='Generic.PHP.CharacterBeforePHPOpeningTag'/>
|
||||
|
||||
<rule ref="Generic.PHP.ForbiddenFunctions">
|
||||
<properties>
|
||||
<!-- Starting phpcs 3.3 we should use this
|
||||
<property name="forbiddenFunctions" type="array">
|
||||
<element key="delete" value="unset"/>
|
||||
<element key="print" value="echo"/>
|
||||
<element key="create_function" value="null"/>
|
||||
<element key="system" value="null"/>
|
||||
<element key="sizeof" value="count"/>
|
||||
</property>
|
||||
-->
|
||||
<property name="forbiddenFunctions" type="array" value="delete=>unset,print=>echo,create_function=>null,system=>null,sizeof=>count" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Internal.NoCodeFound">
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.PHP.DiscouragedFunctions">
|
||||
<properties>
|
||||
<property name="error" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!--
|
||||
Should be introduced later:
|
||||
<rule ref='Generic.PHP.NoSilencedErrorsSniff'/>
|
||||
|
||||
<rule ref="Squiz.Strings.DoubleQuoteUsage.ContainsVar">
|
||||
<type>warning</type>
|
||||
</rule>
|
||||
-->
|
||||
<rule ref='Squiz.PHP.DisallowSizeFunctionsInLoops'/>
|
||||
|
||||
<rule ref='Squiz.Strings.EchoedStrings'/>
|
||||
|
||||
<rule ref="Squiz.Strings.ConcatenationSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="1" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref='PEAR.WhiteSpace'/>
|
||||
<rule ref='Generic.WhiteSpace.DisallowTabIndent'/>
|
||||
|
||||
<rule ref="Generic.Strings.UnnecessaryStringConcat">
|
||||
<properties>
|
||||
<property name="allowMultiline" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
|
||||
<properties>
|
||||
<property name="ignoreNewlines" value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
|
||||
<properties>
|
||||
<!-- <property name="ignoreBlankLines" value="true" /> -->
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Ensure 1 blank line before and after functions, except at the top and bottom. -->
|
||||
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
|
||||
<properties>
|
||||
<property name="spacing" value="1" />
|
||||
<property name="spacingBeforeFirst" value="0" />
|
||||
<property name="spacingAfterLast" value="0" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref='Squiz.WhiteSpace.SemicolonSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.ScopeKeywordSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.ScopeClosingBrace'/>
|
||||
<rule ref='Squiz.WhiteSpace.CastSpacing'/>
|
||||
<rule ref='Squiz.WhiteSpace.FunctionClosingBraceSpace'/>
|
||||
|
||||
<rule ref='Squiz.PHP.Eval'/>
|
||||
<rule ref='Squiz.PHP.DisallowBooleanStatement'/>
|
||||
<rule ref='Squiz.Arrays.ArrayBracketSpacing'/>
|
||||
<!--
|
||||
<rule ref='Squiz.WhiteSpace.MemberVarSpacing'/>
|
||||
<rule ref='Squiz.Operators.ComparisonOperatorUsage'/>
|
||||
CSS
|
||||
-->
|
||||
|
||||
<!-- Include some CSS rules I want to enforce
|
||||
<rule ref='Squiz.CSS.ClassDefinitionOpeningBraceSpace'/>
|
||||
<rule ref='Squiz.CSS.ClassDefinitionClosingBraceSpace'/>
|
||||
<rule ref='Squiz.CSS.Indentation'/>
|
||||
-->
|
||||
<rule ref='Squiz.CSS.DuplicateStyleDefinition'/>
|
||||
<rule ref='Squiz.CSS.ClassDefinitionNameSpacing'/>
|
||||
<rule ref='Squiz.CSS.ColonSpacing'/>
|
||||
<rule ref='Squiz.CSS.EmptyClassDefinition'/>
|
||||
<rule ref='Squiz.CSS.ColourDefinition'/>
|
||||
<rule ref='Squiz.CSS.SemicolonSpacing'/>
|
||||
|
||||
<!-- <rule ref='MySource.CSS.BrowserSpecificStyles'/> -->
|
||||
|
||||
<!--
|
||||
Javascript
|
||||
-->
|
||||
<rule ref='Squiz.Debug.JSLint'/>
|
||||
|
||||
</ruleset>
|
Loading…
Reference in New Issue
Block a user