annotate vendor/squizlabs/php_codesniffer/src/Standards/PSR12/ruleset.xml @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@17 1 <?xml version="1.0"?>
Chris@17 2 <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PSR12" xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">
Chris@17 3 <description>The PSR-12 coding standard.</description>
Chris@17 4 <arg name="tab-width" value="4"/>
Chris@17 5
Chris@17 6 <!-- 2. General -->
Chris@17 7
Chris@17 8 <!-- 2.1 Basic Coding Standard -->
Chris@17 9
Chris@17 10 <!-- Code MUST follow all rules outlined in PSR-1. -->
Chris@17 11 <rule ref="PSR1"/>
Chris@17 12
Chris@18 13 <!-- The term 'StudlyCaps' in PSR-1 MUST be interpreted as PascalCase where the first letter of each word is capitalized including the very first letter. -->
Chris@18 14
Chris@17 15 <!-- 2.2 Files -->
Chris@17 16
Chris@17 17 <!-- All PHP files MUST use the Unix LF (linefeed) line ending only. -->
Chris@17 18 <rule ref="Generic.Files.LineEndings">
Chris@17 19 <properties>
Chris@17 20 <property name="eolChar" value="\n"/>
Chris@17 21 </properties>
Chris@17 22 </rule>
Chris@17 23
Chris@17 24 <!-- All PHP files MUST end with a non-blank line, terminated with a single LF. -->
Chris@17 25 <rule ref="PSR2.Files.EndFileNewline"/>
Chris@17 26
Chris@17 27 <!-- The closing ?> tag MUST be omitted from files containing only PHP. -->
Chris@17 28 <rule ref="PSR2.Files.ClosingTag"/>
Chris@17 29
Chris@17 30 <!-- 2.3 Lines -->
Chris@17 31
Chris@17 32 <!-- There MUST NOT be a hard limit on line length.
Chris@17 33 The soft limit on line length MUST be 120 characters.
Chris@17 34 Lines SHOULD NOT be longer than 80 characters; lines longer than that SHOULD be split into multiple subsequent lines of no more than 80 characters each. -->
Chris@17 35 <rule ref="Generic.Files.LineLength">
Chris@17 36 <properties>
Chris@17 37 <property name="lineLimit" value="120"/>
Chris@17 38 <property name="absoluteLineLimit" value="0"/>
Chris@17 39 </properties>
Chris@17 40 </rule>
Chris@17 41
Chris@17 42 <!-- There MUST NOT be trailing whitespace at the end of lines.
Chris@17 43 Blank lines MAY be added to improve readability and to indicate related blocks of code except where explicitly forbidden. -->
Chris@17 44 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
Chris@17 45 <properties>
Chris@17 46 <property name="ignoreBlankLines" value="true"/>
Chris@17 47 </properties>
Chris@17 48 </rule>
Chris@17 49 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
Chris@17 50 <severity>0</severity>
Chris@17 51 </rule>
Chris@17 52 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
Chris@17 53 <severity>0</severity>
Chris@17 54 </rule>
Chris@17 55 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
Chris@17 56 <severity>0</severity>
Chris@17 57 </rule>
Chris@17 58
Chris@17 59 <!-- There MUST NOT be more than one statement per line. -->
Chris@17 60 <rule ref="Generic.Formatting.DisallowMultipleStatements"/>
Chris@17 61
Chris@17 62 <!-- 2.4 Indenting -->
Chris@17 63
Chris@17 64 <!-- Code MUST use an indent of 4 spaces for each indent level, and MUST NOT use tabs for indenting. -->
Chris@17 65 <rule ref="Generic.WhiteSpace.ScopeIndent">
Chris@17 66 <properties>
Chris@17 67 <property name="ignoreIndentationTokens" type="array">
Chris@17 68 <element value="T_COMMENT"/>
Chris@17 69 <element value="T_DOC_COMMENT_OPEN_TAG"/>
Chris@17 70 </property>
Chris@17 71 </properties>
Chris@17 72 </rule>
Chris@17 73 <rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
Chris@17 74
Chris@17 75 <!-- 2.5 Keywords and Types -->
Chris@17 76
Chris@17 77 <!-- All PHP reserved keywords and types [1][2] MUST be in lower case.
Chris@17 78 Any new types and keywords added to future PHP versions MUST be in lower case. -->
Chris@17 79 <rule ref="Generic.PHP.LowerCaseKeyword"/>
Chris@17 80 <rule ref="Generic.PHP.LowerCaseConstant"/>
Chris@17 81 <rule ref="Generic.PHP.LowerCaseType"/>
Chris@17 82
Chris@17 83 <!-- Short form of type keywords MUST be used i.e. bool instead of boolean, int instead of integer etc. -->
Chris@17 84 <!-- checked by PSR12.Keywords.ShortFormTypeKeywords -->
Chris@17 85
Chris@17 86 <!-- 3. Declare Statements, Namespace, and Import Statements -->
Chris@17 87
Chris@17 88 <!-- The header of a PHP file may consist of a number of different blocks. If present, each of the blocks below MUST be separated by a single blank line, and MUST NOT contain a blank line. Each block MUST be in the order listed below, although blocks that are not relevant may be omitted.
Chris@17 89
Chris@18 90 Opening php tag.
Chris@17 91 File-level docblock.
Chris@17 92 One or more declare statements.
Chris@17 93 The namespace declaration of the file.
Chris@17 94 One or more class-based use import statements.
Chris@17 95 One or more function-based use import statements.
Chris@17 96 One or more constant-based use import statements.
Chris@17 97 The remainder of the code in the file.
Chris@17 98
Chris@18 99 When a file contains a mix of HTML and PHP, any of the above sections may still be used. If so, they MUST be present at the top of the file, even if the remainder of the code consists of a closing PHP tag and then a mixture of HTML and PHP. -->
Chris@18 100
Chris@18 101 <!-- When the opening php tag is on the first line of the file, it MUST be on its own line with no other statements unless it is a file containing markup outside of PHP opening and closing tags. -->
Chris@17 102
Chris@17 103 <!-- Import statements MUST never begin with a leading backslash as they must always be fully qualified. -->
Chris@17 104
Chris@17 105 <!-- Compound namespaces with a depth of more than two MUST NOT be used. -->
Chris@17 106 <!-- checked by PSR12.Namespaces.CompoundNamespaceDepth -->
Chris@17 107
Chris@17 108 <!-- When wishing to declare strict types in files containing markup outside PHP opening and closing tags MUST, on the first line, include an opening PHP tag, the strict types declaration and closing tag. -->
Chris@17 109
Chris@17 110 <!-- Declare statements MUST contain no spaces and MUST be exactly declare(strict_types=1) (with an optional semi-colon terminator). -->
Chris@17 111
Chris@17 112 <!-- Block declare statements are allowed and MUST be formatted as below. -->
Chris@17 113
Chris@17 114 <!-- 4. Classes, Properties, and Methods -->
Chris@17 115
Chris@17 116 <!-- Any closing brace MUST NOT be followed by any comment or statement on the same line. -->
Chris@17 117
Chris@17 118 <!-- When instantiating a new class, parenthesis MUST always be present even when there are no arguments passed to the constructor. -->
Chris@17 119 <!-- checked by PSR12.Classes.ClassInstantiation -->
Chris@17 120
Chris@17 121 <!-- 4.1 Extends and Implements -->
Chris@17 122
Chris@17 123 <!-- The extends and implements keywords MUST be declared on the same line as the class name. -->
Chris@17 124 <!-- The opening brace for the class MUST go on its own line; the closing brace for the class MUST go on the next line after the body. -->
Chris@17 125 <!-- Opening braces MUST be on their own line and MUST NOT be preceded or followed by a blank line. -->
Chris@17 126 <!-- Closing braces MUST be on their own line and MUST NOT be preceded by a blank line. -->
Chris@17 127 <!-- Lists of implements and extends MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one interface per line. -->
Chris@17 128 <rule ref="PSR2.Classes.ClassDeclaration"/>
Chris@17 129
Chris@17 130 <!-- 4.2 Using traits -->
Chris@17 131
Chris@17 132 <!-- The use keyword used inside the classes to implement traits MUST be declared on the next line after the opening brace. -->
Chris@17 133
Chris@18 134 <!-- Each individual Trait that is imported into a class MUST be included one-per-line and each inclusion MUST have its own use import statement. -->
Chris@17 135
Chris@18 136 <!-- When the class has nothing after the use import statement, the class closing brace MUST be on the next line after the use import statement. Otherwise, it MUST have a blank line after the use import statement. -->
Chris@17 137
Chris@17 138 <!-- When using the insteadof and as operators they must be used as follows taking note of indentation, spacing and new lines. -->
Chris@17 139
Chris@17 140 <!-- 4.3 Properties and Constants -->
Chris@17 141
Chris@17 142 <!-- Visibility MUST be declared on all properties. -->
Chris@17 143 <!-- The var keyword MUST NOT be used to declare a property. -->
Chris@17 144 <!-- There MUST NOT be more than one property declared per statement. -->
Chris@18 145 <!-- Property names MUST NOT be prefixed with a single underscore to indicate protected or private visibility.
Chris@18 146 That is, an underscore prefix explicitly has no meaning. -->
Chris@17 147 <rule ref="PSR2.Classes.PropertyDeclaration"/>
Chris@17 148
Chris@17 149 <!-- Visibility MUST be declared on all constants if your project PHP minimum version supports constant visibilities (PHP 7.1 or later). -->
Chris@17 150
Chris@18 151 <!-- There MUST be a space between type declaration and property name. -->
Chris@18 152
Chris@17 153 <!-- 4.4 Methods and Functions -->
Chris@17 154
Chris@17 155 <!-- Visibility MUST be declared on all methods. -->
Chris@17 156 <rule ref="Squiz.Scope.MethodScope"/>
Chris@17 157 <rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
Chris@17 158
Chris@17 159 <!-- Method names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning. -->
Chris@17 160 <rule ref="PSR2.Methods.MethodDeclaration"/>
Chris@17 161 <rule ref="PSR2.Methods.MethodDeclaration.Underscore">
Chris@17 162 <type>error</type>
Chris@17 163 <message>Method name "%s" must not be prefixed with an underscore to indicate visibility</message>
Chris@17 164 </rule>
Chris@17 165
Chris@17 166 <!-- Method and function names MUST NOT be declared with a space after the method name. The opening brace MUST go on its own line, and the closing brace MUST go on the next line following the body. There MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. -->
Chris@17 167 <rule ref="PSR2.Methods.FunctionClosingBrace"/>
Chris@17 168 <rule ref="Squiz.Functions.FunctionDeclaration"/>
Chris@17 169 <rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
Chris@17 170
Chris@17 171 <!-- 4.5 Method and function Arguments -->
Chris@17 172
Chris@17 173 <!-- In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
Chris@17 174 <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
Chris@17 175 <properties>
Chris@17 176 <property name="equalsSpacing" value="1"/>
Chris@17 177 </properties>
Chris@17 178 </rule>
Chris@17 179 <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint">
Chris@17 180 <severity>0</severity>
Chris@17 181 </rule>
Chris@17 182
Chris@17 183 <!-- Method and function arguments with default values MUST go at the end of the argument list. -->
Chris@17 184 <rule ref="PEAR.Functions.ValidDefaultValue"/>
Chris@17 185
Chris@18 186 <!-- Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.
Chris@18 187 When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. -->
Chris@17 188 <rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
Chris@17 189
Chris@17 190 <!-- When you have a return type declaration present there MUST be one space after the colon followed by the type declaration. The colon and declaration MUST be on the same line as the argument list closing parentheses with no spaces between the two characters. -->
Chris@17 191
Chris@18 192 <!-- In nullable type declarations, there MUST NOT be a space between the question mark and the type. -->
Chris@17 193 <!-- checked by PSR12.Functions.NullableTypeDeclaration -->
Chris@17 194
Chris@18 195 <!-- When using the reference operator & before an argument, there MUST NOT be a space after it. -->
Chris@18 196
Chris@18 197 <!-- There MUST NOT be a space between the variadic three dots and the argument name. -->
Chris@18 198
Chris@18 199 <!-- When combining both the reference operator and the variadic three dots, there MUST NOT be any space between the two of them. -->
Chris@18 200
Chris@17 201 <!-- 4.6 abstract, final, and static -->
Chris@17 202
Chris@17 203 <!-- When present, the abstract and final declarations MUST precede the visibility declaration. -->
Chris@17 204 <!-- When present, the static declaration MUST come after the visibility declaration. -->
Chris@17 205 <!-- checked by PSR2.Methods.MethodDeclaration included above -->
Chris@17 206
Chris@17 207 <!-- 4.7 Method and Function Calls -->
Chris@17 208
Chris@17 209 <!-- When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis, there MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
Chris@17 210 <!-- Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. A single argument being split across multiple lines (as might be the case with an anonymous function or array) does not constitute splitting the argument list itself. -->
Chris@17 211 <rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
Chris@17 212 <rule ref="PSR2.Methods.FunctionCallSignature"/>
Chris@17 213 <rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
Chris@17 214 <severity>0</severity>
Chris@17 215 </rule>
Chris@17 216 <rule ref="PSR2.Methods.FunctionCallSignature.OpeningIndent">
Chris@17 217 <severity>0</severity>
Chris@17 218 </rule>
Chris@17 219
Chris@17 220 <!-- 5. Control Structures -->
Chris@17 221
Chris@17 222 <!-- The general style rules for control structures are as follows:
Chris@17 223 There MUST be one space after the control structure keyword
Chris@17 224 There MUST NOT be a space after the opening parenthesis
Chris@17 225 There MUST NOT be a space before the closing parenthesis
Chris@17 226 There MUST be one space between the closing parenthesis and the opening brace
Chris@17 227 The structure body MUST be indented once
Chris@17 228 The closing brace MUST be on the next line after the body
Chris@18 229 The body of each structure MUST be enclosed by braces. This standardizes how the structures look and reduces the likelihood of introducing errors as new lines get added to the body. -->
Chris@17 230 <rule ref="Squiz.ControlStructures.ControlSignature"/>
Chris@17 231 <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
Chris@17 232 <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
Chris@17 233 <rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
Chris@17 234 <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
Chris@17 235 <rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
Chris@18 236 <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
Chris@18 237 <severity>0</severity>
Chris@18 238 </rule>
Chris@18 239 <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
Chris@18 240 <severity>0</severity>
Chris@18 241 </rule>
Chris@17 242 <rule ref="Squiz.ControlStructures.LowercaseDeclaration"/>
Chris@17 243 <rule ref="PSR2.ControlStructures.ControlStructureSpacing"/>
Chris@17 244 <rule ref="Generic.ControlStructures.InlineControlStructure"/>
Chris@17 245
Chris@17 246 <!-- exclude this message as it is already checked in Generic.PHP.LowerCaseKeyword -->
Chris@17 247 <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
Chris@17 248 <severity>0</severity>
Chris@17 249 </rule>
Chris@17 250
Chris@17 251 <!-- 5.1 if, elseif, else -->
Chris@17 252
Chris@17 253 <!-- else and elseif are on the same line as the closing brace from the earlier body. -->
Chris@17 254
Chris@17 255 <!-- The keyword elseif SHOULD be used instead of else if so that all control keywords look like single words. -->
Chris@17 256 <rule ref="PSR2.ControlStructures.ElseIfDeclaration"/>
Chris@17 257
Chris@17 258 <!-- Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first condition MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line with one space between them. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both. -->
Chris@17 259
Chris@17 260 <!-- 5.2 switch, case -->
Chris@17 261
Chris@17 262 <!-- The case statement MUST be indented once from switch, and the break keyword (or other terminating keywords) MUST be indented at the same level as the case body. There MUST be a comment such as // no break when fall-through is intentional in a non-empty case body. -->
Chris@17 263 <rule ref="PSR2.ControlStructures.SwitchDeclaration"/>
Chris@17 264
Chris@17 265 <!-- Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first condition MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line with one space between them. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both. -->
Chris@17 266
Chris@18 267 <!-- 5.3.1 while -->
Chris@18 268
Chris@18 269 <!-- Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first condition MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line with one space between them. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both. -->
Chris@18 270
Chris@18 271 <!-- 5.3.2 do while -->
Chris@17 272
Chris@17 273 <!-- Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first condition MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line. Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both. -->
Chris@17 274
Chris@17 275 <!-- 5.4 for -->
Chris@17 276
Chris@17 277 <!-- Expressions in parentheses MAY be split across multiple lines, where each subsequent line is indented at least once. When doing so, the first expression MUST be on the next line. The closing parenthesis and opening brace MUST be placed together on their own line with one space between them. -->
Chris@17 278
Chris@17 279 <!-- 5.5 foreach -->
Chris@17 280
Chris@17 281 <!-- 5.6 try, catch, finally -->
Chris@17 282
Chris@17 283 <!-- 6. Operators -->
Chris@17 284
Chris@18 285 <!-- All binary and ternary operators MUST be preceded and followed by at least one space; multiple spaces MAY be used for readability purpose. This includes all arithmetic, comparison, assignment, bitwise, logical (excluding ! which is unary), string concatenation, type operators, trait operators (insteadof and as), and the single pipe operator (e.g. ExceptionType1 | ExceptionType2 $e). -->
Chris@18 286 <!-- checked by PSR12.Operators.OperatorSpacing -->
Chris@18 287
Chris@18 288 <!-- There MUST NOT be any whitespace between the increment/decrement operators and the variable being incremented/decremented. -->
Chris@18 289 <rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
Chris@18 290
Chris@17 291 <!-- Other operators are left undefined. -->
Chris@17 292
Chris@17 293 <!-- 7. Closures -->
Chris@17 294
Chris@17 295 <!-- Closures MUST be declared with a space after the function keyword, and a space before and after the use keyword. -->
Chris@17 296 <!-- The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body. -->
Chris@17 297 <!-- There MUST NOT be a space after the opening parenthesis of the argument list or variable list, and there MUST NOT be a space before the closing parenthesis of the argument list or variable list. -->
Chris@17 298 <!-- In the argument list and variable list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
Chris@17 299 <!-- Closure arguments with default values MUST go at the end of the argument list. -->
Chris@17 300 <!-- Argument lists and variable lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument or variable per line. -->
Chris@17 301 <!-- When the ending list (whether of arguments or variables) is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. -->
Chris@17 302 <!-- checked by Squiz.Functions.MultiLineFunctionDeclaration -->
Chris@17 303
Chris@18 304 <!-- If a return type is present, it MUST follow the same rules as with normal functions and methods; if the use keyword is present, the colon MUST follow the use list closing parentheses with no spaces between the two characters. -->
Chris@18 305
Chris@17 306 <!-- 8. Anonymous Classes -->
Chris@17 307
Chris@17 308 <!-- Anonymous Classes MUST follow the same guidelines and principles as closures in the above section. -->
Chris@17 309
Chris@18 310 <!-- The opening brace MAY be on the same line as the class keyword so long as the list of implements interfaces does not wrap. If the list of interfaces wraps, the brace MUST be placed on the line immediately following the last interface. -->
Chris@18 311
Chris@18 312 <!-- 9. Type Casting -->
Chris@18 313
Chris@18 314 <!-- There MUST NOT be any spaces inside the type casting parentheses. -->
Chris@18 315 <rule ref="Squiz.WhiteSpace.CastSpacing"/>
Chris@17 316
Chris@17 317 </ruleset>