Skip to content

Commit 37be691

Browse files
committed
PER CS 3.0: 4. Classes, Properties, and Methods
1 parent 673eefd commit 37be691

File tree

1 file changed

+93
-26
lines changed

1 file changed

+93
-26
lines changed

src/Standards/PER-CS3.0/ruleset.xml

Lines changed: 93 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -144,37 +144,42 @@
144144
<!-- When instantiating a new class, parentheses MUST always be present even when there are no arguments passed to the constructor. -->
145145
<!-- checked by PSR12.Classes.ClassInstantiation -->
146146

147+
<!-- If class contains no additional declarations (such as an exception that exists only to extend another exception with a new type), then the body of the class SHOULD be abbreviated as {} and placed on the same line as the previous symbol, separated by a space. -->
148+
<!-- When accessing a class member immediately after instantiating a new class, the instantiation SHOULD NOT be wrapped in parentheses. -->
149+
<!--todo-->
150+
147151
<!-- 4.1 Extends and Implements -->
148152

149153
<!-- The extends and implements keywords MUST be declared on the same line as the class name. -->
150-
<!-- 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. -->
151-
<!-- Opening braces MUST be on their own line and MUST NOT be preceded or followed by a blank line. -->
152-
<!-- Closing braces MUST be on their own line and MUST NOT be preceded by a blank line. -->
154+
<!-- The opening brace for the class MUST go on its own line, and MUST NOT be preceded or followed by a blank line. -->
155+
<!-- The closing brace for the class MUST go on its own line, immediately following the last line of the class body, and MUST NOT be preceded by a blank line. -->
153156
<!-- Lists of implements and, in the case of interfaces, 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. -->
154157
<!-- checked by PSR12.Classes.OpeningBraceSpace -->
155158
<rule ref="PSR2.Classes.ClassDeclaration"/>
159+
<!--todo-->
156160

157161
<!-- 4.2 Using traits -->
158162

159163
<!-- The use keyword used inside the classes to implement traits MUST be declared on the next line after the opening brace. -->
160164
<!-- 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. -->
161165
<!-- 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. -->
162-
<!-- When using the insteadof and as operators they must be used as follows taking note of indentation, spacing, and new lines. -->
166+
<!-- When using the insteadof and as operators they MUST be used as follows taking note of indentation, spacing, and new lines. -->
163167
<!-- checked by PSR12.Traits.UseDeclaration -->
164168

165169
<!-- 4.3 Properties and Constants -->
166170

167-
<!-- Visibility MUST be declared on all properties. -->
171+
<!-- Visibility MUST be declared on all properties. If set-visibility is specified, then the general visibility MAY be omitted. -->
172+
<!--todo-->
173+
<!-- Visibility MUST be declared on all constants. -->
174+
<!-- checked by PSR12.Properties.ConstantVisibility -->
175+
168176
<!-- The var keyword MUST NOT be used to declare a property. -->
169-
<!-- There MUST NOT be more than one property declared per statement. -->
170-
<!-- Property names MUST NOT be prefixed with a single underscore to indicate protected or private visibility.
171-
That is, an underscore prefix explicitly has no meaning. -->
177+
<!-- There MUST NOT be more than one property or constant declared per statement. -->
178+
<!--todo-->
179+
<!-- Property or constant names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning. -->
172180
<!-- There MUST be a space between type declaration and property name. -->
173181
<rule ref="PSR2.Classes.PropertyDeclaration"/>
174182

175-
<!-- Visibility MUST be declared on all constants if your project PHP minimum version supports constant visibilities (PHP 7.1 or later). -->
176-
<!-- checked by PSR12.Properties.ConstantVisibility -->
177-
178183
<!-- 4.4 Methods and Functions -->
179184

180185
<!-- Visibility MUST be declared on all methods. -->
@@ -193,19 +198,13 @@
193198
<rule ref="Squiz.Functions.FunctionDeclaration"/>
194199
<rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
195200

196-
<!-- 4.5 Method and Function Arguments -->
201+
<!-- If a function or method contains no statements or comments (such as an empty no-op implementation or when using constructor property promotion), then the body SHOULD be abbreviated as {} and placed on the same line as the previous symbol, separated by a space. -->
202+
<!--todo-->
197203

198-
<!-- In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
199-
<!-- When using the reference operator & before an argument, there MUST NOT be a space after it. -->
200-
<!-- There MUST NOT be a space between the variadic three dot operator and the argument name. -->
201-
<!-- When combining both the reference operator and the variadic three dot operator, there MUST NOT be any space between the two of them. -->
202-
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
203-
<properties>
204-
<property name="equalsSpacing" value="1"/>
205-
</properties>
206-
</rule>
204+
<!-- 4.5 Method and Function Parameters -->
207205

208-
<!-- Method and function arguments with default values MUST go at the end of the argument list. -->
206+
<!-- In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. -->
207+
<!-- Method and function parameters with default values MUST go at the end of the argument list. -->
209208
<rule ref="PEAR.Functions.ValidDefaultValue"/>
210209

211210
<!-- 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.
@@ -218,16 +217,33 @@
218217
<!-- In nullable type declarations, there MUST NOT be a space between the question mark and the type. -->
219218
<!-- checked by PSR12.Functions.NullableTypeDeclaration -->
220219

221-
<!-- 4.6 abstract, final, and static -->
220+
<!-- When using the reference operator & before an argument, there MUST NOT be a space after it. -->
221+
<!-- There MUST NOT be a space between the variadic three dot operator and the argument name. -->
222+
<!-- When combining both the reference operator and the variadic three dot operator, there MUST NOT be any space between the two of them. -->
223+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
224+
<properties>
225+
<property name="equalsSpacing" value="1"/>
226+
</properties>
227+
</rule>
222228

223-
<!-- When present, the abstract and final declarations MUST precede the visibility declaration. -->
224-
<!-- When present, the static declaration MUST come after the visibility declaration. -->
229+
<!-- 4.6 Modifier Keywords -->
230+
231+
<!-- Classes, properties, and methods have numerous keyword modifiers that alter how the engine and language handles them. When present, they MUST be in the following order:
232+
Inheritance modifier: abstract or final
233+
Visibility modifier: public, protected, or private
234+
Set-visibility modifier: public(set), protected(set), or private(set)
235+
Scope modifier: static
236+
Mutation modifier: readonly
237+
Type declaration
238+
Name
239+
All keywords MUST be on a single line, and MUST be separated by a single space. All keywords MUST be all lower-case. The public keyword MAY be omitted when using a set-visibility on a public-read property. -->
225240
<!-- checked by PSR2.Methods.MethodDeclaration included above -->
241+
<!--todo-->
226242

227243
<!-- 4.7 Method and Function Calls -->
228244

229245
<!-- 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. -->
230-
<!-- 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. -->
246+
<!-- 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 a closure or array) does not constitute splitting the argument list itself. -->
231247
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
232248
<rule ref="PSR2.Methods.FunctionCallSignature"/>
233249
<rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket">
@@ -237,6 +253,57 @@
237253
<severity>0</severity>
238254
</rule>
239255

256+
<!-- If using named arguments, there MUST NOT be a space between the argument name and colon, and there MUST be a single space between the colon and the argument value. -->
257+
<!-- Method chaining MAY be put on separate lines, where each subsequent line is indented once. When doing so, the first method MUST be on the next line. -->
258+
<!-- The exit() and die() functions SHOULD always be called with parentheses even if no argument is given to clearly distinguish them from an access to a constant named exit or die. -->
259+
<!--todo-->
260+
261+
<!-- 4.8 Function Callable References -->
262+
263+
<!-- A function or method may be referenced in a way that creates a closure out of it, by providing ... in place of arguments. -->
264+
<!-- If so, the ... MUST NOT include any whitespace before or after. That is, the correct format is foo(...). -->
265+
<!--todo-->
266+
267+
<!-- 4.9 Property Hooks -->
268+
269+
<!-- Object properties may also include hooks, which have a number of syntactic options. -->
270+
<!-- When using the long form of hooks:
271+
The opening brace MUST be on the same line as the property.
272+
The opening brace MUST be separated from the property name or its default value by a single space.
273+
The closing brace MUST be on its own line, and have no comment following it.
274+
The entire body of the hook definition MUST be indented one level.
275+
The body of each hook MUST be indented one level.
276+
If multiple hooks are declared, they MUST be separated by at least a single line break. They MAY be separated by an additional blank line to aid readability. -->
277+
<!-- Property hooks also support multiple short-hook variations. -->
278+
<!-- For a set hook, if the argument name and type do not need to be redefined, then they MAY be omitted. -->
279+
<!-- If a hook consists of a single expression, then PHP allows it to be shortened using =>. In that case:
280+
There MUST be a single space on either side of the => symbol.
281+
The body MUST begin on the same line as the hook name and =>.
282+
Wrapping is allowed if the expression used allows for wrapping, using the rules defined elsewhere in this document. -->
283+
<!-- Additionally, if the following criteria are met:
284+
There is only one hook implementation.
285+
That hook uses the short-hook syntax.
286+
That hook expression does not contain any wrapping.
287+
Then the hook MAY be listed entirely inline. In that case,
288+
The hook name MUST be separated from the opening brace and the arrow operator by a single space
289+
The semicolon ending of the hook MUST be separated from the closing brace by a single space. -->
290+
<!-- Property hooks MAY also be defined in constructor-promoted properties. However, they MUST be only a single hook, with a short-syntax body, defined on a single line as above. If those criteria are not met, then the promoted property MUST NOT have any hooks defined inline. -->
291+
<!--todo-->
292+
293+
<!-- 4.10 Interface and abstract properties -->
294+
295+
<!-- Abstract properties may be defined in interfaces or abstract classes, but are required to specify if they must support get operations, set operations, or both. In the case of abstract classes, they MAY include a body for one or another hook. -->
296+
<!-- If there is a body for any hook, then the entire hook block MUST follow the same rules as for defined hooks above. The only difference is that a hook that has no body specified have a single semicolon after the hook keyword, with no space before it. -->
297+
<!-- If there is no body for either hook, then the following rules apply:
298+
The operation block MUST be on the same line as the property.
299+
There MUST be a single space between the property name and the operation block {}.
300+
There MUST be a single space after the opening {.
301+
There MUST be a single space before the closing };
302+
There MUST NOT be a space between the operation and its required semicolon.
303+
If multiple operations are specified, they MUST be separated by a single space.
304+
The get operation MUST be listed before the set operation. -->
305+
<!--todo-->
306+
240307
<!-- 5. Control Structures -->
241308

242309
<!-- The general style rules for control structures are as follows:

0 commit comments

Comments
 (0)