| 
39 | 39 |     </rule>  | 
40 | 40 | 
 
  | 
41 | 41 | 
 
  | 
 | 42 | +    <!--  | 
 | 43 | +    ####################################################################  | 
 | 44 | +    PHP: Modernize a codebase when possible.  | 
 | 45 | +    ####################################################################  | 
 | 46 | +    -->  | 
 | 47 | + | 
 | 48 | +    <rule ref="Modernize.FunctionCalls.Dirname.FileConstant"/>  | 
 | 49 | + | 
 | 50 | + | 
42 | 51 |     <!--  | 
43 | 52 |     ####################################################################  | 
44 | 53 |     Code style: Check style for compliance with PSR12.  | 
 | 
81 | 90 |         </properties>  | 
82 | 91 |     </rule>  | 
83 | 92 | 
 
  | 
 | 93 | +    <!-- Prevent PHP 8 named parameters confusion. -->  | 
 | 94 | +    <rule ref="Universal.NamingConventions.NoReservedKeywordParameterNames"/>  | 
 | 95 | + | 
84 | 96 | 
 
  | 
85 | 97 |     <!--  | 
86 | 98 |     ####################################################################  | 
87 | 99 |     Code style: Various other additions.  | 
 | 100 | +    Some of these rules will probably be enforced via PERCS once it is available, but we already want to use them.  | 
88 | 101 |     ####################################################################  | 
89 | 102 |     -->  | 
90 | 103 | 
 
  | 
 | 104 | +    <!-- Enforce lowercase PHP tags. -->  | 
 | 105 | +    <rule ref="Universal.PHP.LowercasePHPTag"/>  | 
 | 106 | + | 
 | 107 | +    <!-- Enforce consistency in import use statements. -->  | 
 | 108 | +    <rule ref="Universal.UseStatements.NoLeadingBackslash"/>  | 
 | 109 | +    <rule ref="Universal.UseStatements.KeywordSpacing"/>  | 
 | 110 | +    <rule ref="Universal.UseStatements.LowercaseFunctionConst"/>  | 
 | 111 | + | 
 | 112 | +    <!-- Consistent modifier keyword order. PSR12 currently only enforces this for property declarations. -->  | 
 | 113 | +    <rule ref="Universal.Classes.ModifierKeywordOrder"/>  | 
 | 114 | +    <rule ref="Universal.Constants.ModifierKeywordOrder"/>  | 
 | 115 | + | 
91 | 116 |     <!-- PSR12 doesn't enforce consistency in where boolean operators are placed. We do. -->  | 
92 | 117 |     <rule ref="PSR12.ControlStructures.BooleanOperatorPlacement">  | 
93 | 118 |         <properties>  | 
94 | 119 |             <property name="allowOnly" value="first"/>  | 
95 | 120 |         </properties>  | 
96 | 121 |     </rule>  | 
97 | 122 | 
 
  | 
 | 123 | +    <!-- Same thing, but then for multi-line concatenation in statements. -->  | 
 | 124 | +    <rule ref="Universal.Operators.ConcatPosition">  | 
 | 125 | +        <properties>  | 
 | 126 | +            <property name="allowOnly" value="start"/>  | 
 | 127 | +        </properties>  | 
 | 128 | +    </rule>  | 
 | 129 | + | 
98 | 130 |     <!-- PSR12 appears to ignore blank lines for superfluous whitespace and in several other places. Let's fix that. -->  | 
99 | 131 |     <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">  | 
100 | 132 |         <properties>  | 
 | 
129 | 161 |     <!-- No spacing inside heredoc/nowdocs identifiers. -->  | 
130 | 162 |     <rule ref="Generic.WhiteSpace.HereNowdocIdentifierSpacing"/>  | 
131 | 163 | 
 
  | 
 | 164 | +    <!-- No spaces around type operators. -->  | 
 | 165 | +    <rule ref="Universal.Operators.TypeSeparatorSpacing"/>  | 
 | 166 | + | 
 | 167 | +    <!-- Always use parentheses when instantiating anonymous classes. -->  | 
 | 168 | +    <rule ref="Universal.Classes.RequireAnonClassParentheses"/>  | 
 | 169 | + | 
 | 170 | +    <!-- No space between the class keyword and the open parentheses for anonymous classes. -->  | 
 | 171 | +    <rule ref="Universal.WhiteSpace.AnonClassKeywordSpacing"/>  | 
 | 172 | + | 
 | 173 | +    <!-- Enforce consistent spacing around commas (no space before, one space or new line after). -->  | 
 | 174 | +    <rule ref="Universal.WhiteSpace.CommaSpacing">  | 
 | 175 | +        <exclude name="Universal.WhiteSpace.CommaSpacing.TooMuchSpaceAfterCommaBeforeTrailingComment"/>  | 
 | 176 | +    </rule>  | 
 | 177 | + | 
 | 178 | +    <!-- Disallow precision alignment (indentation). -->  | 
 | 179 | +    <rule ref="Universal.WhiteSpace.PrecisionAlignment"/>  | 
 | 180 | + | 
132 | 181 |     <!-- Align the equal operator in assignment blocks. -->  | 
133 | 182 |     <rule ref="Generic.Formatting.MultipleStatementAlignment">  | 
134 | 183 |         <properties>  | 
 | 
148 | 197 |     <!-- Disallow Yoda conditions. -->  | 
149 | 198 |     <rule ref="Generic.ControlStructures.DisallowYodaConditions"/>  | 
150 | 199 | 
 
  | 
 | 200 | +    <!-- Disallow alternative syntax for control structures. -->  | 
 | 201 | +    <rule ref="Universal.ControlStructures.DisallowAlternativeSyntax"/>  | 
 | 202 | + | 
151 | 203 |     <!-- Use self or static when referring to the class in use. -->  | 
152 | 204 |     <rule ref="Squiz.Classes.SelfMemberReference"/>  | 
 | 205 | +    <rule ref="Universal.CodeAnalysis.StaticInFinalClass"/>  | 
 | 206 | + | 
 | 207 | +    <!-- Only one namespace per file. -->  | 
 | 208 | +    <rule ref="Universal.Namespaces.OneDeclarationPerFile"/>  | 
 | 209 | + | 
 | 210 | +    <!-- Don't allow curly brace syntax for namespace declarations. -->  | 
 | 211 | +    <rule ref="Universal.Namespaces.DisallowCurlyBraceSyntax"/>  | 
153 | 212 | 
 
  | 
154 | 213 |     <!-- Only one object structure per file. -->  | 
155 | 214 |     <rule ref="Generic.Files.OneObjectStructurePerFile"/>  | 
156 | 215 | 
 
  | 
 | 216 | +    <!-- And don't mix OO declarations and function declarations in one file. -->  | 
 | 217 | +    <rule ref="Universal.Files.SeparateFunctionsFromOO"/>  | 
 | 218 | + | 
157 | 219 |     <!-- Disallow non-strict comparisons and the use of the not operator. -->  | 
158 | 220 |     <rule ref="Squiz.Operators.ComparisonOperatorUsage">  | 
159 | 221 |         <exclude name="Squiz.Operators.ComparisonOperatorUsage.ImplicitTrue"/>  | 
160 | 222 |     </rule>  | 
161 | 223 | 
 
  | 
 | 224 | +    <!-- Enforce lowercase ::class. -->  | 
 | 225 | +    <rule ref="Universal.Constants.LowercaseClassResolutionKeyword"/>  | 
 | 226 | + | 
 | 227 | +    <!-- PHP native magic constants should be uppercase. -->  | 
 | 228 | +    <rule ref="Universal.Constants.UppercaseMagicConstants"/>  | 
 | 229 | + | 
 | 230 | +    <!-- Alphabetize lists of extended and implemented interfaces. -->  | 
 | 231 | +    <rule ref="Universal.OOStructures.AlphabeticExtendsImplements"/>  | 
 | 232 | + | 
 | 233 | +    <!-- Disallow the use of fully qualified true/false/null. -->  | 
 | 234 | +    <rule ref="Universal.PHP.NoFQNTrueFalseNull"/>  | 
 | 235 | + | 
 | 236 | +    <!-- Prevent really long lists with all (global) functions/constants used in a file. -->  | 
 | 237 | +    <rule ref="Universal.UseStatements.DisallowUseConst"/>  | 
 | 238 | +    <rule ref="Universal.UseStatements.DisallowUseFunction"/>  | 
 | 239 | + | 
162 | 240 | 
 
  | 
163 | 241 |     <!--  | 
164 | 242 |     ####################################################################  | 
165 | 243 |     Code style: Array declarations.  | 
166 | 244 |     ####################################################################  | 
167 | 245 |     -->  | 
168 | 246 | 
 
  | 
 | 247 | +    <!-- This (incomplete) ruleset may cause some duplication for now, but that will be fixed once  | 
 | 248 | +         the ruleset is completed and we can remove the `Squiz.Arrays.ArrayDeclaration` sniff. -->  | 
 | 249 | +    <rule ref="NormalizedArrays"/>  | 
 | 250 | + | 
169 | 251 |     <!-- Enforce short array syntax. -->  | 
170 | 252 |     <rule ref="Generic.Arrays.DisallowLongArraySyntax"/>  | 
171 | 253 | 
 
  | 
 | 
226 | 308 |     </rule>  | 
227 | 309 | 
 
  | 
228 | 310 | 
 
  | 
 | 311 | +    <!--  | 
 | 312 | +    ####################################################################  | 
 | 313 | +    PHPCS compatibility additions.  | 
 | 314 | +    ####################################################################  | 
 | 315 | +    -->  | 
 | 316 | + | 
 | 317 | +    <!-- The PHPCS autoloader does not handle sniffs which extends other sniffs well, so prevent problems by making all sniffs final. -->  | 
 | 318 | +    <rule ref="Universal.Classes.RequireFinalClass"/>  | 
 | 319 | + | 
 | 320 | +    <!-- Enforce methods in traits to be final to prevent (accidental) overloading. -->  | 
 | 321 | +    <rule ref="Universal.FunctionDeclarations.RequireFinalMethodsInTraits"/>  | 
 | 322 | + | 
 | 323 | + | 
229 | 324 |     <!--  | 
230 | 325 |     ####################################################################  | 
231 | 326 |     Code Analysis additions.  | 
232 | 327 |     ####################################################################  | 
233 | 328 |     -->  | 
234 | 329 | 
 
  | 
 | 330 | +    <!-- Testability: long closures make for code which is more difficult to test. -->  | 
 | 331 | +    <rule ref="Universal.FunctionDeclarations.NoLongClosures">  | 
 | 332 | +        <!-- Disable the warning after 5 lines, only have the error after 8 lines. -->  | 
 | 333 | +        <properties>  | 
 | 334 | +            <property name="recommendedLines " value="1000"/>  | 
 | 335 | +        </properties>  | 
 | 336 | +    </rule>  | 
 | 337 | + | 
235 | 338 |     <!-- Efficiency: don't use function calls within the condition of a for loop. -->  | 
236 | 339 |     <rule ref="Generic.CodeAnalysis.ForLoopWithTestFunctionCall"/>  | 
237 | 340 | 
 
  | 
 | 
244 | 347 |     <!-- Efficiency: don't unnecessarily use heredocs. -->  | 
245 | 348 |     <rule ref="Generic.Strings.UnnecessaryHeredoc"/>  | 
246 | 349 | 
 
  | 
 | 350 | +    <!-- Efficiency: simplify code when possible. -->  | 
 | 351 | +    <rule ref="Universal.CodeAnalysis.NoEchoSprintf"/>  | 
 | 352 | + | 
247 | 353 |     <!-- Error prevention: warns when an inner loop uses the same incrementor as the outer loop. -->  | 
248 | 354 |     <rule ref="Generic.CodeAnalysis.JumbledIncrementer"/>  | 
249 | 355 | 
 
  | 
 | 
255 | 361 |     <!-- Error prevention: use parentheses when mixing boolean operators. -->  | 
256 | 362 |     <rule ref="Generic.CodeAnalysis.RequireExplicitBooleanOperatorPrecedence"/>  | 
257 | 363 | 
 
  | 
 | 364 | +    <!-- Error prevention: Don't allow mixed arrays (keyed/non-keyed). -->  | 
 | 365 | +    <rule ref="Universal.Arrays.MixedKeyedUnkeyedArray"/>  | 
 | 366 | + | 
 | 367 | +    <!-- Error prevention: Don't allow mixed arrays (integer/string keys). -->  | 
 | 368 | +    <rule ref="Universal.Arrays.MixedArrayKeyTypes"/>  | 
 | 369 | + | 
 | 370 | +    <!-- Error prevention: Prevent issues with duplicate arrays keys. -->  | 
 | 371 | +    <rule ref="Universal.Arrays.DuplicateArrayKey"/>  | 
 | 372 | + | 
 | 373 | +    <!-- Error prevention: Prevent issues with precedent order. -->  | 
 | 374 | +    <rule ref="Universal.Operators.DisallowLogicalAndOr"/>  | 
 | 375 | + | 
 | 376 | +    <!-- Error prevention: Prevent logic errors as most devs don't understand short ternary well enough. -->  | 
 | 377 | +    <rule ref="Universal.Operators.DisallowShortTernary"/>  | 
 | 378 | + | 
 | 379 | +    <!-- Error prevention: Prevent issues when in/decremented variables get moved around and are suddenly no longer stand-alone. -->  | 
 | 380 | +    <rule ref="Universal.Operators.DisallowStandalonePostIncrementDecrement"/>  | 
 | 381 | + | 
 | 382 | +    <!-- Error prevention: Prevent creation of constructor/destructors which will not work as expected. -->  | 
 | 383 | +    <rule ref="Universal.CodeAnalysis.ConstructorDestructorReturn"/>  | 
 | 384 | + | 
 | 385 | +    <!-- Error prevention: Prevent unpredictable code behaviour. -->  | 
 | 386 | +    <rule ref="Universal.CodeAnalysis.ForeachUniqueAssignment"/>  | 
 | 387 | + | 
 | 388 | +    <!-- Error prevention: Prevent incomprehensible code. -->  | 
 | 389 | +    <rule ref="Universal.CodeAnalysis.NoDoubleNegative"/>  | 
 | 390 | + | 
 | 391 | +    <!-- Error prevention: don't allow people to do silly things. -->  | 
 | 392 | +    <rule ref="Universal.PHP.OneStatementInShortEchoTag"/>  | 
 | 393 | + | 
258 | 394 |     <!-- Clean up: remove redundant code. -->  | 
259 | 395 |     <rule ref="Squiz.PHP.NonExecutableCode">  | 
260 | 396 |         <!-- Allow for return statement in otherwise empty function. -->  | 
 | 
264 | 400 |     <!-- Clean up: no empty statements. -->  | 
265 | 401 |     <rule ref="Generic.CodeAnalysis.EmptyPHPStatement"/>  | 
266 | 402 | 
 
  | 
 | 403 | +    <!-- Clean up: no lonely if statements. -->  | 
 | 404 | +    <rule ref="Universal.ControlStructures.DisallowLonelyIf"/>  | 
 | 405 | + | 
 | 406 | +    <!-- Clean up: no useless aliases in import use statements. -->  | 
 | 407 | +    <rule ref="Universal.UseStatements.NoUselessAliases"/>  | 
 | 408 | + | 
267 | 409 |     <!-- Parse error prevention: guard against merge conflict artifacts. -->  | 
268 | 410 |     <rule ref="Generic.VersionControl.GitMergeConflict"/>  | 
269 | 411 | 
 
  | 
 | 412 | +    <!-- Lower cognitive load. -->  | 
 | 413 | +    <rule ref="Universal.UseStatements.DisallowMixedGroupUse"/>  | 
 | 414 | + | 
270 | 415 | </ruleset>  | 
0 commit comments