|
3 | 3 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
4 | 4 | xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/squizlabs/PHP_CodeSniffer/master/phpcs.xsd"
|
5 | 5 | name="Syntatis">
|
6 |
| - <description>PHP Coding Standard</description> |
| 6 | + <description>Curated Coding Standard for PHP</description> |
7 | 7 |
|
8 |
| - <!-- Use colors in output --> |
9 |
| - <arg name="colors"/> |
| 8 | + <!-- |
| 9 | + Trigger error if PHPCSUtils cannot be found. |
| 10 | + PHPCSUtils does not contain any sniffs, so this rule isn't strictly necessary, but |
| 11 | + by having this here anyway, if PHPCSUtils is missing, the user will get a |
| 12 | + descriptive error message during the loading of the ruleset instead of |
| 13 | + a fatal "class not found" error once the sniffs start running. |
| 14 | + --> |
| 15 | + <rule ref="PHPCSUtils"/> |
10 | 16 |
|
11 |
| - <!-- Show progress of the run --> |
12 |
| - <arg value="p"/> |
13 |
| - |
14 |
| - <!-- Show sniff codes in all reports --> |
15 |
| - <arg value="s"/> |
16 |
| - |
17 |
| - <!-- Only check files with PHP extension --> |
18 |
| - <arg name="extensions" value="php"/> |
19 |
| - |
20 |
| - <!-- Show the warning but exit with 0. The Warning is fine --> |
21 |
| - <config name="ignore_warnings_on_exit" value="1"/> |
22 |
| - |
23 |
| - <!-- Include full Doctrine Coding Standard --> |
| 17 | + <!-- Doctrine and Slevomat rules --> |
24 | 18 | <rule ref="Doctrine">
|
25 | 19 | <exclude name="Generic.Formatting.MultipleStatementAlignment"/>
|
26 | 20 | <exclude name="Generic.WhiteSpace.DisallowTabIndent"/>
|
27 | 21 | <exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
|
28 | 22 | <exclude name="SlevomatCodingStandard.PHP.RequireExplicitAssertion"/>
|
29 | 23 |
|
30 |
| - <!-- Some of the projects still require to support PHP 7.4 which does not support the follow features --> |
| 24 | + <!-- Skip features not in PHP 7.4 --> |
31 | 25 | <exclude name="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
|
32 | 26 | <exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/>
|
33 | 27 | </rule>
|
34 | 28 | <rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
|
35 | 29 | <properties>
|
36 | 30 | <property name="annotationsGroups" type="array">
|
37 | 31 | <element value="@phpcsSuppress"/>
|
38 |
| - <!-- |
39 |
| - Tests annotation |
40 |
| - @link https://phpunit.readthedocs.io/en/7.0/annotations.html |
41 |
| - The @author annotation is excluded from the list, use @group or @ticket instead. |
42 |
| - --> |
| 32 | + <!-- PHPUnit annotations (see link) --> |
43 | 33 | <element value="
|
44 | 34 | @after,
|
45 | 35 | @afterClass,
|
|
68 | 58 | @ticket,
|
69 | 59 | @uses"
|
70 | 60 | />
|
71 |
| - <!-- Psalm annotations essentially overrides PHP docBlocks --> |
72 |
| - <element value="@phpstan-consistent-constructor, @phpstan-import-type, @phpstan-type, @psalm-consistent-constructor, @psalm-import-type, @phpstan-type"/> |
| 61 | + <!-- Psalm & PHPStan annotations --> |
| 62 | + <element value=" |
| 63 | + @phpstan-consistent-constructor, |
| 64 | + @phpstan-import-type, |
| 65 | + @phpstan-type, |
| 66 | + @psalm-consistent-constructor, |
| 67 | + @psalm-import-type, |
| 68 | + @psalm-type" |
| 69 | + /> |
73 | 70 | <element value="@template, @template-implements, @template-extends"/>
|
74 | 71 | <element value="@example, @see, @link, @todo"/>
|
75 | 72 | <element value="@method, @property"/>
|
|
86 | 83 | <exclude-pattern>/tests/</exclude-pattern>
|
87 | 84 | </rule>
|
88 | 85 |
|
89 |
| - <!-- Generic --> |
90 |
| - <rule ref="Generic.Files.LineLength"> |
91 |
| - <properties> |
92 |
| - <property name="ignoreComments" value="true"/> |
93 |
| - </properties> |
| 86 | + <!-- Avoid using the "goto" statement --> |
| 87 | + <rule ref="Generic.PHP.DiscourageGoto"> |
| 88 | + <type>error</type> |
| 89 | + <message>The "goto" language construct should not be used.</message> |
94 | 90 | </rule>
|
| 91 | + |
| 92 | + <!-- "eval()" is a security risk, so don't use it --> |
| 93 | + <rule ref="Squiz.PHP.Eval.Discouraged"> |
| 94 | + <type>error</type> |
| 95 | + <message>eval() is a security risk so not allowed.</message> |
| 96 | + </rule> |
| 97 | + |
| 98 | + <!-- PHP tags for multiline PHP code in HTML should be on their own lines --> |
| 99 | + <rule ref="Squiz.PHP.EmbeddedPhp"/> |
| 100 | + |
| 101 | + <!-- Always use full PHP tags, not shorthand --> |
| 102 | + <rule ref="Generic.PHP.DisallowShortOpenTag"/> |
| 103 | + <rule ref="Generic.PHP.DisallowAlternativePHPTags"/> |
| 104 | + |
| 105 | + <!-- Prefer require[_once] for unconditional includes --> |
| 106 | + <rule ref="PEAR.Files.IncludingFile.UseRequire"> |
| 107 | + <type>warning</type> |
| 108 | + </rule> |
| 109 | + <rule ref="PEAR.Files.IncludingFile.UseRequireOnce"> |
| 110 | + <type>warning</type> |
| 111 | + </rule> |
| 112 | + <!-- Prevent issues with content before headers --> |
| 113 | + <rule ref="Generic.Files.ByteOrderMark"/> |
| 114 | + |
| 115 | + <!-- Magic constants (__*__) should be uppercase --> |
| 116 | + <rule ref="Universal.Constants.UppercaseMagicConstants"/> |
| 117 | + |
| 118 | + <!-- The ::class keyword should be lowercase --> |
| 119 | + <rule ref="Universal.Constants.LowercaseClassResolutionKeyword"/> |
| 120 | + |
| 121 | + <!-- Only one namespace declaration per file --> |
| 122 | + <rule ref="Universal.Namespaces.OneDeclarationPerFile"/> |
| 123 | + |
| 124 | + <!-- Don't use curly brace syntax for namespaces --> |
| 125 | + <rule ref="Universal.Namespaces.DisallowCurlyBraceSyntax"/> |
| 126 | + |
| 127 | + <!-- No explicit global namespace declarations --> |
| 128 | + <rule ref="Universal.Namespaces.DisallowDeclarationWithoutName"/> |
| 129 | + |
| 130 | + <!-- Prefer __DIR__ over dirname(__FILE__) and use dirname(__DIR__, $levels) over nested dirname() --> |
| 131 | + <rule ref="Modernize.FunctionCalls.Dirname"/> |
| 132 | + |
| 133 | + <!-- Avoid ambiguous conditions --> |
| 134 | + <rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/> |
| 135 | + |
| 136 | + <!-- Use real tabs and not spaces. --> |
95 | 137 | <rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
|
96 |
| - <rule ref="Generic.WhiteSpace.ScopeIndent"> |
| 138 | + <rule ref="Universal.WhiteSpace.PrecisionAlignment"/> |
| 139 | + |
| 140 | + <!-- Ensure functions use all passed parameters --> |
| 141 | + <rule ref="Generic.CodeAnalysis.UnusedFunctionParameter"> |
| 142 | + <!-- Allow for callbacks that may not use all parameters --> |
| 143 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed"/> |
| 144 | + <!-- Allow for extended class/interface functions --> |
| 145 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass"/> |
| 146 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed"/> |
| 147 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed"/> |
| 148 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterface"/> |
| 149 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceBeforeLastUsed"/> |
| 150 | + <exclude name="Generic.CodeAnalysis.UnusedFunctionParameter.FoundInImplementedInterfaceAfterLastUsed"/> |
| 151 | + </rule> |
| 152 | + |
| 153 | + <!-- All line endings should be \n. --> |
| 154 | + <rule ref="Generic.Files.LineEndings"> |
97 | 155 | <properties>
|
98 |
| - <property name="indent" value="4" /> |
99 |
| - <property name="tabIndent" value="true" /> |
| 156 | + <property name="eolChar" value="\n"/> |
100 | 157 | </properties>
|
101 | 158 | </rule>
|
102 |
| - <rule ref="Generic.Files.LineLength.TooLong"> |
103 |
| - <exclude-pattern>/tests/</exclude-pattern> |
| 159 | + |
| 160 | + <!-- Don't commit commented-out code --> |
| 161 | + <rule ref="Squiz.PHP.CommentedOutCode"> |
| 162 | + <properties> |
| 163 | + <property name="maxPercentage" value="40"/> |
| 164 | + </properties> |
104 | 165 | </rule>
|
| 166 | + |
| 167 | + <!-- Always have a lowertag PHP open tag. --> |
| 168 | + <rule ref="Universal.PHP.LowercasePHPTag"/> |
| 169 | + |
| 170 | + <!-- Check for duplicate array keys --> |
| 171 | + <rule ref="Universal.Arrays.DuplicateArrayKey"/> |
| 172 | + |
| 173 | + <!-- No return types for constructors/destructors, or returning values --> |
| 174 | + <rule ref="Universal.CodeAnalysis.ConstructorDestructorReturn"/> |
| 175 | + |
| 176 | + <!-- Detect foreach loops using the same variable for key and value --> |
| 177 | + <rule ref="Universal.CodeAnalysis.ForeachUniqueAssignment"/> |
| 178 | + |
| 179 | + <!-- Use self instead of static in final classes --> |
| 180 | + <rule ref="Universal.CodeAnalysis.StaticInFinalClass"/> |
| 181 | + |
| 182 | + <!-- Avoid if statements as the only statement in an else block --> |
| 183 | + <rule ref="Universal.ControlStructures.DisallowLonelyIf"/> |
| 184 | + |
| 185 | + <!-- Separate functions and object-oriented code --> |
| 186 | + <rule ref="Universal.Files.SeparateFunctionsFromOO"/> |
| 187 | + |
| 188 | + <!-- Detect useless "echo sprintf(...)" --> |
| 189 | + <rule ref="Universal.CodeAnalysis.NoEchoSprintf"/> |
| 190 | + |
| 191 | + <!-- Avoid double negatives "!!" --> |
| 192 | + <rule ref="Universal.CodeAnalysis.NoDoubleNegative"/> |
| 193 | + |
| 194 | + <!-- Avoid reserved keywords as function parameter names. --> |
| 195 | + <rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames"/> |
| 196 | + |
| 197 | + <!-- General PHP best practices --> |
| 198 | + <rule ref="Generic.PHP.BacktickOperator"/> |
| 199 | + <rule ref="Universal.UseStatements.NoUselessAliases"/> |
| 200 | + <rule ref="Squiz.Functions.FunctionDuplicateArgument"/> |
| 201 | + <rule ref="Squiz.PHP.DisallowSizeFunctionsInLoops"/> |
| 202 | + <rule ref="Squiz.Operators.IncrementDecrementUsage"/> |
105 | 203 | </ruleset>
|
0 commit comments