Skip to content

Commit 4b91d28

Browse files
Feat: add config file for PHP Code Sniffer
Thanks to @mattf for his outstanding work on this!
1 parent 060c123 commit 4b91d28

File tree

2 files changed

+255
-0
lines changed

2 files changed

+255
-0
lines changed

phpcs.xml

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="phpBB extension coding standard" xsi:noNamespaceSchemaLocation="phpcs.xsd" namespace="Phpbb">
3+
<description>phpBB extension coding standard</description>
4+
5+
<!--
6+
1.i. Editor Settings
7+
http://area51.phpbb.com/docs/32x/coding-guidelines.html#editorsettings
8+
-->
9+
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent"/>
10+
<rule ref="Generic.Files.LineEndings"/>
11+
12+
<!--
13+
1.ii. File Layout
14+
http://area51.phpbb.com/docs/32x/coding-guidelines.html#fileheader
15+
-->
16+
<rule ref="PSR2.Files.ClosingTag"/>
17+
<rule ref="Generic.Files.EndFileNewline"/>
18+
19+
<!--
20+
2.i. Variable/Function/Class Naming
21+
http://area51.phpbb.com/docs/32x/coding-guidelines.html#namingvars
22+
-->
23+
<!-- variable names are checked using Phpbb.NamingConventions.LowercaseUnderscoredVariables -->
24+
<!-- function names are checked using Phpbb.NamingConventions.LowercaseUnderscoredFunctions -->
25+
<!-- class names are checked using Phpbb.NamingConventions.LowercaseUnderscoredClasses -->
26+
<rule ref="Generic.Files.OneClassPerFile"/>
27+
<rule ref="Generic.Files.OneInterfacePerFile"/>
28+
<rule ref="Generic.Files.LowercasedFilename"/>
29+
<!-- TODO: create a sniff verifying that namespace matches directory structure -->
30+
31+
<!--
32+
2.ii. Code Layout
33+
http://area51.phpbb.com/docs/32x/coding-guidelines.html#codelayout
34+
-->
35+
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
36+
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
37+
<!-- opening brace for controls is checked using Phpbb.ControlStructure.OpeningBraceBsdAllman -->
38+
<!-- a space before opening parenthesis checked using Phpbb.ControlStructure.OpeningParenthesis -->
39+
<!-- TODO: create a sniff that checks for spaces between tokens -->
40+
<rule ref="Generic.WhiteSpace.ArbitraryParenthesesSpacing"/>
41+
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
42+
<!-- TODO: create a sniff validating that break; is on the same level as case -->
43+
<rule ref="Squiz.Scope.MemberVarScope"/>
44+
<rule ref="Squiz.Scope.MethodScope"/>
45+
46+
<!--
47+
2.vi. Restrictions on the Use of PHP
48+
http://area51.phpbb.com/docs/32x/coding-guidelines.html#phprestrictions
49+
-->
50+
<rule ref="Generic.PHP.DiscourageGoto"/>
51+
52+
<!--
53+
Other useful rules copied from phpbb repo
54+
-->
55+
<!-- The PHP constants true, false, and null MUST be in lower case. -->
56+
<rule ref="Generic.PHP.LowerCaseConstant"/>
57+
<!-- PHP keywords MUST be in lower case. -->
58+
<rule ref="Generic.PHP.LowerCaseKeyword"/>
59+
<!-- Constructors MUST be called __construct() instead of after the class. -->
60+
<rule ref="Generic.NamingConventions.ConstructorName"/>
61+
<!-- Classes etc. MUST be namespaced -->
62+
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
63+
<!-- Files containing classes MUST not have any side-effects -->
64+
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols"/>
65+
<!-- When present, all use declarations MUST go after the namespace declaration.
66+
There MUST be one use keyword per declaration.
67+
There MUST be one blank line after the use block. -->
68+
<rule ref="PSR2.Namespaces.UseDeclaration"/>
69+
<!-- There MUST be one blank line after the namespace declaration -->
70+
<rule ref="PSR2.Namespaces.NamespaceDeclaration"/>
71+
<!-- "for (; bar; )" should be "while (bar)" instead -->
72+
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
73+
<!-- A method MUST not only call its parent -->
74+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
75+
<!-- There MUST not be more than one statement per line. -->
76+
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
77+
<!-- Call-time pass-by-reference MUST not be used. -->
78+
<rule ref="Generic.Functions.CallTimePassByReference.NotAllowed"/>
79+
<!-- There MUST be exactly one space after a cast. -->
80+
<rule ref="Generic.Formatting.SpaceAfterCast"/>
81+
<!-- Class constants MUST be declared in all upper case with underscore separators. -->
82+
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
83+
<!-- Only <?php, no short tags. -->
84+
<rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound"/>
85+
<!-- Method arguments with default values MUST go at the end of the argument list. -->
86+
<rule ref="PEAR.Functions.ValidDefaultValue"/>
87+
<!-- When referencing arrays there MUST NOT be any whitespace around the opening bracket
88+
or before the closing bracket. -->
89+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
90+
<!-- The "else if" statement MUST be written with a space between the words else and if. -->
91+
<rule ref="Squiz.ControlStructures.ElseIfDeclaration"/>
92+
<!-- There MUST be a space between each element of a foreach loop. -->
93+
<rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/>
94+
<!-- In a for loop declaration, there MUST be no space inside the brackets
95+
and there MUST be 0 spaces before and 1 space after semicolons. -->
96+
<rule ref="Squiz.ControlStructures.ForLoopDeclaration"/>
97+
<!-- In the argument list, there MUST NOT be a space before each comma,
98+
and there MUST be one space after each comma. -->
99+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing">
100+
<properties>
101+
<property name="equalsSpacing" value="1"/>
102+
</properties>
103+
</rule>
104+
<rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint"/>
105+
<!-- All built-in PHP functions MUST be called lowercased. -->
106+
<rule ref="Squiz.Functions.LowercaseFunctionKeywords"/>
107+
<!-- The eval() function MUST NOT be used. -->
108+
<rule ref="Squiz.PHP.Eval"/>
109+
<!-- There MUST NOT be trailing whitespace at the end of lines. -->
110+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
111+
<!-- There MUST NOT be whitespace before the first content of a file -->
112+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile"/>
113+
<!-- There MUST NOT be whitespace after the last content of a file -->
114+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile"/>
115+
<!-- Functions MUST NOT contain multiple empty lines in a row -->
116+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines"/>
117+
<!-- All code files MUST use only UTF-8 without BOM. -->
118+
<rule ref="Generic.Files.ByteOrderMark"/>
119+
</ruleset>

phpcs.xsd

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
3+
4+
<xs:element name="ruleset">
5+
<xs:complexType>
6+
<xs:choice minOccurs="0" maxOccurs="unbounded">
7+
<xs:element name="description" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
8+
<xs:element name="config" maxOccurs="unbounded" minOccurs="0">
9+
<xs:complexType>
10+
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
11+
<xs:attribute name="value" type="xs:string" use="required"></xs:attribute>
12+
<xs:attributeGroup ref="applySelectively"/>
13+
</xs:complexType>
14+
</xs:element>
15+
<xs:element name="file" maxOccurs="unbounded" minOccurs="0">
16+
<xs:complexType>
17+
<xs:simpleContent>
18+
<xs:extension base="xs:string">
19+
<xs:attributeGroup ref="applySelectively"/>
20+
</xs:extension>
21+
</xs:simpleContent>
22+
</xs:complexType>
23+
</xs:element>
24+
<xs:element name="exclude-pattern" type="patternType" maxOccurs="unbounded" minOccurs="0"></xs:element>
25+
<xs:element name="arg" maxOccurs="unbounded" minOccurs="0">
26+
<xs:complexType>
27+
<xs:attribute name="name" type="xs:string"></xs:attribute>
28+
<xs:attribute name="value" type="xs:string"></xs:attribute>
29+
<xs:attributeGroup ref="applySelectively"/>
30+
</xs:complexType>
31+
</xs:element>
32+
<xs:element name="ini" maxOccurs="unbounded" minOccurs="0">
33+
<xs:complexType>
34+
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
35+
<xs:attribute name="value" type="xs:string" use="required"></xs:attribute>
36+
<xs:attributeGroup ref="applySelectively"/>
37+
</xs:complexType>
38+
</xs:element>
39+
<xs:element name="autoload" type="xs:string" maxOccurs="unbounded" minOccurs="0"></xs:element>
40+
<xs:element name="rule" type="ruleType" maxOccurs="unbounded" minOccurs="0"></xs:element>
41+
</xs:choice>
42+
<xs:attribute name="name" type="xs:string"></xs:attribute>
43+
<xs:attribute name="namespace" type="xs:string"></xs:attribute>
44+
</xs:complexType>
45+
</xs:element>
46+
47+
<xs:complexType name="ruleType">
48+
<xs:choice minOccurs="0" maxOccurs="unbounded">
49+
<xs:element name="exclude" maxOccurs="unbounded" minOccurs="0">
50+
<xs:complexType>
51+
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
52+
<xs:attributeGroup ref="applySelectively"/>
53+
</xs:complexType>
54+
</xs:element>
55+
<xs:element name="message" type="xs:string" maxOccurs="1" minOccurs="0"></xs:element>
56+
<xs:element name="severity" maxOccurs="1" minOccurs="0">
57+
<xs:complexType>
58+
<xs:simpleContent>
59+
<xs:extension base="xs:integer">
60+
<xs:attributeGroup ref="applySelectively"/>
61+
</xs:extension>
62+
</xs:simpleContent>
63+
</xs:complexType>
64+
</xs:element>
65+
<xs:element name="type" maxOccurs="1" minOccurs="0">
66+
<xs:complexType>
67+
<xs:simpleContent>
68+
<xs:extension base="messageType">
69+
<xs:attributeGroup ref="applySelectively"/>
70+
</xs:extension>
71+
</xs:simpleContent>
72+
</xs:complexType>
73+
</xs:element>
74+
<xs:element name="exclude-pattern" type="patternType" maxOccurs="unbounded" minOccurs="0"></xs:element>
75+
<xs:element name="include-pattern" type="patternType" maxOccurs="unbounded" minOccurs="0"></xs:element>
76+
<xs:element name="properties" type="propertiesType" maxOccurs="1" minOccurs="0"></xs:element>
77+
</xs:choice>
78+
<xs:attribute name="ref" type="xs:string" use="required"></xs:attribute>
79+
<xs:attributeGroup ref="applySelectively"/>
80+
</xs:complexType>
81+
82+
<xs:complexType name="patternType">
83+
<xs:simpleContent>
84+
<xs:extension base="xs:string">
85+
<xs:attribute name="type">
86+
<xs:simpleType>
87+
<xs:restriction base="xs:string">
88+
<xs:enumeration value="relative"></xs:enumeration>
89+
</xs:restriction>
90+
</xs:simpleType>
91+
</xs:attribute>
92+
<xs:attributeGroup ref="applySelectively"/>
93+
</xs:extension>
94+
</xs:simpleContent>
95+
</xs:complexType>
96+
97+
<xs:complexType name="propertiesType">
98+
<xs:sequence>
99+
<xs:element name="property" maxOccurs="unbounded" minOccurs="1">
100+
<xs:complexType>
101+
<xs:sequence>
102+
<xs:element name="element" maxOccurs="unbounded" minOccurs="0">
103+
<xs:complexType>
104+
<xs:attribute name="key" type="xs:string"></xs:attribute>
105+
<xs:attribute name="value" type="xs:string" use="required"></xs:attribute>
106+
</xs:complexType>
107+
</xs:element>
108+
</xs:sequence>
109+
<xs:attribute name="type">
110+
<xs:simpleType>
111+
<xs:restriction base="xs:string">
112+
<xs:enumeration value="array"></xs:enumeration>
113+
</xs:restriction>
114+
</xs:simpleType>
115+
</xs:attribute>
116+
<xs:attribute name="name" type="xs:string" use="required"></xs:attribute>
117+
<xs:attribute name="value" type="xs:string"></xs:attribute>
118+
<xs:attribute name="extend" type="xs:boolean" default="false"/>
119+
<xs:attributeGroup ref="applySelectively"/>
120+
</xs:complexType>
121+
</xs:element>
122+
</xs:sequence>
123+
</xs:complexType>
124+
125+
<xs:simpleType name="messageType">
126+
<xs:restriction base="xs:string">
127+
<xs:enumeration value="error"></xs:enumeration>
128+
<xs:enumeration value="warning"></xs:enumeration>
129+
</xs:restriction>
130+
</xs:simpleType>
131+
132+
<xs:attributeGroup name="applySelectively">
133+
<xs:attribute name="phpcs-only" type="xs:boolean" default="false"/>
134+
<xs:attribute name="phpcbf-only" type="xs:boolean" default="false"/>
135+
</xs:attributeGroup>
136+
</xs:schema>

0 commit comments

Comments
 (0)