Chris@17
|
1 <?xml version="1.0"?>
|
Chris@17
|
2 <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PSR2" xsi:noNamespaceSchemaLocation="../../../phpcs.xsd">
|
Chris@17
|
3 <description>The PSR-2 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 <!-- Include the whole PSR-1 standard -->
|
Chris@17
|
11 <rule ref="PSR1"/>
|
Chris@17
|
12
|
Chris@17
|
13 <!-- 2.2 Files -->
|
Chris@17
|
14
|
Chris@17
|
15 <!-- All PHP files MUST use the Unix LF (linefeed) line ending. -->
|
Chris@17
|
16 <rule ref="Generic.Files.LineEndings">
|
Chris@17
|
17 <properties>
|
Chris@17
|
18 <property name="eolChar" value="\n"/>
|
Chris@17
|
19 </properties>
|
Chris@17
|
20 </rule>
|
Chris@17
|
21
|
Chris@17
|
22 <!-- All PHP files MUST end with a single blank line. -->
|
Chris@17
|
23 <!-- checked by PSR2.Files.EndFileNewline -->
|
Chris@17
|
24
|
Chris@17
|
25 <!-- The closing ?> tag MUST be omitted from files containing only PHP. -->
|
Chris@17
|
26 <!-- checked by PSR2.Files.ClosingTag -->
|
Chris@17
|
27
|
Chris@17
|
28 <!-- 2.3 Lines -->
|
Chris@17
|
29
|
Chris@17
|
30 <!-- The soft limit on line length MUST be 120 characters; automated style checkers MUST warn but MUST NOT error at the soft limit. -->
|
Chris@17
|
31 <rule ref="Generic.Files.LineLength">
|
Chris@17
|
32 <properties>
|
Chris@17
|
33 <property name="lineLimit" value="120"/>
|
Chris@17
|
34 <property name="absoluteLineLimit" value="0"/>
|
Chris@17
|
35 </properties>
|
Chris@17
|
36 </rule>
|
Chris@17
|
37
|
Chris@17
|
38 <!-- There MUST NOT be trailing whitespace at the end of non-blank lines. -->
|
Chris@17
|
39 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
|
Chris@17
|
40 <properties>
|
Chris@17
|
41 <property name="ignoreBlankLines" value="true"/>
|
Chris@17
|
42 </properties>
|
Chris@17
|
43 </rule>
|
Chris@17
|
44 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile">
|
Chris@17
|
45 <severity>0</severity>
|
Chris@17
|
46 </rule>
|
Chris@17
|
47 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile">
|
Chris@17
|
48 <severity>0</severity>
|
Chris@17
|
49 </rule>
|
Chris@17
|
50 <rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
|
Chris@17
|
51 <severity>0</severity>
|
Chris@17
|
52 </rule>
|
Chris@17
|
53
|
Chris@17
|
54 <!-- There MUST NOT be more than one statement per line. -->
|
Chris@17
|
55 <rule ref="Generic.Formatting.DisallowMultipleStatements"/>
|
Chris@17
|
56
|
Chris@17
|
57 <!-- 2.4 Indenting -->
|
Chris@17
|
58
|
Chris@17
|
59 <!-- Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting. -->
|
Chris@17
|
60 <rule ref="Generic.WhiteSpace.ScopeIndent">
|
Chris@17
|
61 <properties>
|
Chris@17
|
62 <property name="ignoreIndentationTokens" type="array">
|
Chris@17
|
63 <element value="T_COMMENT"/>
|
Chris@17
|
64 <element value="T_DOC_COMMENT_OPEN_TAG"/>
|
Chris@17
|
65 </property>
|
Chris@17
|
66 </properties>
|
Chris@17
|
67 </rule>
|
Chris@17
|
68 <rule ref="Generic.WhiteSpace.DisallowTabIndent"/>
|
Chris@17
|
69
|
Chris@17
|
70 <!-- 2.5 Keywords and True/False/Null -->
|
Chris@17
|
71
|
Chris@17
|
72 <!-- PHP keywords MUST be in lower case. -->
|
Chris@17
|
73 <rule ref="Generic.PHP.LowerCaseKeyword"/>
|
Chris@17
|
74
|
Chris@17
|
75 <!-- The PHP constants true, false, and null MUST be in lower case. -->
|
Chris@17
|
76 <rule ref="Generic.PHP.LowerCaseConstant"/>
|
Chris@17
|
77
|
Chris@17
|
78 <!-- 3. Namespace and Use Declarations -->
|
Chris@17
|
79
|
Chris@17
|
80 <!-- When present, there MUST be one blank line after the namespace declaration. -->
|
Chris@17
|
81 <!-- checked by PSR2.Namespaces.NamespaceDeclaration -->
|
Chris@17
|
82
|
Chris@17
|
83 <!-- When present, all use declarations MUST go after the namespace declaration.
|
Chris@17
|
84 There MUST be one use keyword per declaration.
|
Chris@17
|
85 There MUST be one blank line after the use block. -->
|
Chris@17
|
86 <!-- checked by PSR2.Namespaces.UseDeclaration -->
|
Chris@17
|
87
|
Chris@17
|
88 <!-- 4. Classes, Properties, and Methods -->
|
Chris@17
|
89
|
Chris@17
|
90 <!-- 4.1. Extends and Implements -->
|
Chris@17
|
91
|
Chris@17
|
92 <!-- The extends and implements keywords MUST be declared on the same line as the class name.
|
Chris@17
|
93 The opening brace for the class go MUST go on its own line; the closing brace for the class MUST go on the next line after the body.
|
Chris@17
|
94 Lists of implements 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
|
95 <!-- checked by PSR2.Classes.ClassDeclaration -->
|
Chris@17
|
96
|
Chris@17
|
97 <!-- 4.2. Properties -->
|
Chris@17
|
98
|
Chris@17
|
99 <!-- Visibility MUST be declared on all properties.
|
Chris@17
|
100 The var keyword MUST NOT be used to declare a property.
|
Chris@17
|
101 There MUST NOT be more than one property declared per statement.
|
Chris@17
|
102 Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility. -->
|
Chris@17
|
103 <!-- checked by PSR2.Classes.PropertyDeclaration -->
|
Chris@17
|
104
|
Chris@17
|
105 <!-- 4.3 Methods -->
|
Chris@17
|
106
|
Chris@17
|
107 <!-- Visibility MUST be declared on all methods. -->
|
Chris@17
|
108 <rule ref="Squiz.Scope.MethodScope"/>
|
Chris@17
|
109 <rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/>
|
Chris@17
|
110
|
Chris@17
|
111 <!-- Method names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility. -->
|
Chris@17
|
112 <!-- checked by PSR2.Methods.MethodDeclaration -->
|
Chris@17
|
113
|
Chris@17
|
114 <!-- Method 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
|
115 <!-- checked by PSR2.Methods.FunctionClosingBrace -->
|
Chris@17
|
116 <rule ref="Squiz.Functions.FunctionDeclaration"/>
|
Chris@17
|
117 <rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
|
Chris@17
|
118
|
Chris@17
|
119 <!-- 4.4 Method Arguments -->
|
Chris@17
|
120
|
Chris@17
|
121 <!-- In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
|
Chris@17
|
122 <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
|
Chris@17
|
123 <properties>
|
Chris@17
|
124 <property name="equalsSpacing" value="1"/>
|
Chris@17
|
125 </properties>
|
Chris@17
|
126 </rule>
|
Chris@17
|
127 <rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint">
|
Chris@17
|
128 <severity>0</severity>
|
Chris@17
|
129 </rule>
|
Chris@17
|
130
|
Chris@17
|
131 <!-- Method arguments with default values MUST go at the end of the argument list. -->
|
Chris@17
|
132 <rule ref="PEAR.Functions.ValidDefaultValue"/>
|
Chris@17
|
133
|
Chris@17
|
134 <!-- 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. 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
|
135 <rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/>
|
Chris@17
|
136
|
Chris@17
|
137 <!-- 4.5 abstract, final, and static -->
|
Chris@17
|
138
|
Chris@17
|
139 <!-- When present, the abstract and final declarations MUST precede the visibility declaration.
|
Chris@17
|
140 When present, the static declaration MUST come after the visibility declaration. -->
|
Chris@17
|
141 <!-- checked by PSR2.Methods.MethodDeclaration -->
|
Chris@17
|
142
|
Chris@17
|
143 <!-- 4.6 Method and Function Calls -->
|
Chris@17
|
144
|
Chris@17
|
145 <!-- 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
|
146 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@17
|
147 <rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
|
Chris@17
|
148 <rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
|
Chris@17
|
149 <severity>0</severity>
|
Chris@17
|
150 </rule>
|
Chris@17
|
151 <rule ref="PSR2.Methods.FunctionCallSignature.OpeningIndent">
|
Chris@17
|
152 <severity>0</severity>
|
Chris@17
|
153 </rule>
|
Chris@17
|
154
|
Chris@17
|
155 <!-- 5. Control Structures -->
|
Chris@17
|
156
|
Chris@17
|
157 <!-- The general style rules for control structures are as follows:
|
Chris@17
|
158 There MUST be one space after the control structure keyword
|
Chris@17
|
159 There MUST NOT be a space after the opening parenthesis
|
Chris@17
|
160 There MUST NOT be a space before the closing parenthesis
|
Chris@17
|
161 There MUST be one space between the closing parenthesis and the opening brace
|
Chris@17
|
162 The structure body MUST be indented once
|
Chris@17
|
163 The closing brace MUST be on the next line after the body -->
|
Chris@17
|
164 <rule ref="Squiz.ControlStructures.ControlSignature"/>
|
Chris@17
|
165 <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
|
Chris@17
|
166 <rule ref="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
|
Chris@17
|
167 <rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/>
|
Chris@17
|
168 <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
|
Chris@17
|
169 <rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
|
Chris@18
|
170 <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingAfterOpen">
|
Chris@18
|
171 <severity>0</severity>
|
Chris@18
|
172 </rule>
|
Chris@18
|
173 <rule ref="Squiz.ControlStructures.ForLoopDeclaration.SpacingBeforeClose">
|
Chris@18
|
174 <severity>0</severity>
|
Chris@18
|
175 </rule>
|
Chris@17
|
176 <rule ref="Squiz.ControlStructures.LowercaseDeclaration"/>
|
Chris@17
|
177 <!-- checked by PSR2.ControlStructures.ControlStructureSpacing -->
|
Chris@17
|
178
|
Chris@17
|
179 <!-- exclude this message as it is already checked Generic.PHP.LowerCaseKeyword -->
|
Chris@17
|
180 <rule ref="Squiz.ControlStructures.ForEachLoopDeclaration.AsNotLower">
|
Chris@17
|
181 <severity>0</severity>
|
Chris@17
|
182 </rule>
|
Chris@17
|
183
|
Chris@17
|
184 <!-- 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
|
185 <rule ref="Generic.ControlStructures.InlineControlStructure"/>
|
Chris@17
|
186
|
Chris@17
|
187 <!-- 5.1. if, elseif, else -->
|
Chris@17
|
188
|
Chris@17
|
189 <!-- The keyword elseif SHOULD be used instead of else if so that all control keywords look like single words. -->
|
Chris@17
|
190 <!-- checked by PSR2.ControlStructures.ElseIfDeclaration -->
|
Chris@17
|
191
|
Chris@17
|
192 <!-- 5.2. switch, case -->
|
Chris@17
|
193
|
Chris@17
|
194 <!-- The case statement MUST be indented once from switch, and the break keyword (or other terminating keyword) 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
|
195 <!-- checked by PSR2.ControlStructures.SwitchDeclaration -->
|
Chris@17
|
196
|
Chris@17
|
197 <!-- 6. Closures -->
|
Chris@17
|
198
|
Chris@17
|
199 <!-- Closures MUST be declared with a space after the function keyword, and a space before and after the use keyword.
|
Chris@17
|
200 The opening brace MUST go on the same line, and the closing brace MUST go on the next line following the body.
|
Chris@17
|
201 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
|
202 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
|
203 Closure arguments with default values MUST go at the end of the argument list.
|
Chris@17
|
204 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
|
205 When the ending list (whether or 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
|
206 <!-- checked in Squiz.Functions.MultiLineFunctionDeclaration -->
|
Chris@17
|
207 </ruleset>
|