Skip to content

Commit f5ef9ed

Browse files
committed
Improved docs
1 parent 474c546 commit f5ef9ed

13 files changed

+397
-40
lines changed

Inpsyde/Sniffs/CodeQuality/ElementNameMinimalLengthSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function process(File $file, $position)
6666
$this->minLength
6767
);
6868

69-
$file->addError($message, $position, 'ElementNameMinimalLength');
69+
$file->addError($message, $position, 'TooShort');
7070
}
7171

7272
/**

Inpsyde/Sniffs/CodeQuality/ForbiddenPublicPropertySniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function process(File $file, $position)
5454
$file->addError(
5555
'Do not use public properties. Use method access instead.',
5656
$position,
57-
'ForbiddenPublicProperty'
57+
'Found'
5858
);
5959
}
6060
}

Inpsyde/Sniffs/CodeQuality/FunctionLengthSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function process(File $file, $position)
5252
$this->maxLength
5353
);
5454

55-
$file->addError($error, $position, 'FunctionLength');
55+
$file->addError($error, $position, 'TooLong');
5656
}
5757
}
5858

Inpsyde/Sniffs/CodeQuality/MaxNestingLevelSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private function handleNestingLevel(int $nestingLevel)
105105
$nestingLevel
106106
);
107107

108-
$this->file->addError($error, $this->position, 'MaxNestingLevel');
108+
$this->file->addError($error, $this->position, 'TooNested');
109109
}
110110
}
111111

Inpsyde/Sniffs/CodeQuality/PropertyPerClassLimitSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function process(File $file, $position)
5656
$this->maxCount
5757
);
5858

59-
$file->addWarning($message, $position, 'PropertyPerClassLimit');
59+
$file->addWarning($message, $position, 'TooMuchProperties');
6060
}
6161
}
6262
}

Inpsyde/ruleset.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,6 @@
7171
<!--
7272
Generic and common sense sanity.
7373
-->
74-
<rule ref="Generic.ControlStructures.InlineControlStructure"/>
75-
<rule ref="Generic.Files.ByteOrderMark"/>
76-
<rule ref="Generic.Files.LineEndings">
77-
<properties>
78-
<property name="eolChar" value="\n"/>
79-
</properties>
80-
</rule>
8174
<rule ref="Squiz.PHP.Eval"/>
8275

8376
<!--

README.md

Lines changed: 127 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,45 @@ internationalization functions are called with the proper text domain.
9191

9292
## PSR-1 & PSR-2
9393

94-
See http://www.php-fig.org/psr/psr-1/ and http://www.php-fig.org/psr/psr-2/
94+
See http://www.php-fig.org/psr/psr-1/ and http://www.php-fig.org/psr/psr-2/.
95+
96+
The tree of used rules are listed in the `/docs/rules-list/psr.md` file in this repo.
9597

9698

9799
## VariableAnalysis
98100

99101
See https://github.com/sirbrillig/phpcs-variable-analysis
100102

103+
The tree of used rules are listed in the `/docs/rules-list/variable-analysis.md` file in this repo.
104+
101105

102106
## Neutron Standard
103107

104108
See https://github.com/Automattic/phpcs-neutron-standard
105109

106-
All Neutron Standard rules are included except "Function size" (handles in custom rules, see below)
107-
and "Variable Functions" rules.
110+
Almost all Neutron Standard rules are included.
111+
112+
The tree of used rules are listed in the `/docs/rules-list/neutron-standard.md` file in this repo.
113+
114+
115+
## WordPress Coding Standard
116+
117+
To ensure code quality, and compatibility with VIP, several WordPress Coding Standard rules have been
118+
"cherry picked" from WP coding standards.
119+
120+
See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.
121+
122+
The tree of used rules are listed in the `/docs/rules-list/wordpress.md` file in this repo.
123+
124+
125+
## Generic Rules
126+
127+
Some rules are also included from PHP cCode Sniffer itself. Those rules fall in the
128+
"Generic", "Squiz" and "PEAR" namespace.
129+
130+
Those rules are included by other styles, mainly by PSR-1 and PSR-2.
131+
132+
The tree of used rules are listed in the `/docs/rules-list/generic.md` file in this repo.
108133

109134

110135
## Custom Rules
@@ -122,47 +147,121 @@ Customs rules are:
122147
- Max 10 properties per class
123148
- Max 50 lines per method
124149

150+
The tree of used rules are listed in the `/docs/rules-list/custom.md` file in this repo.
125151

126-
## WordPress Coding Standard
152+
-------------
127153

128-
To ensure code quality, and compatibility with VIP, several WordPress Coding Standard rules have been
129-
"cherry picked" from WP coding standards.
130-
See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.
154+
# Removing or Disabling Rules
155+
156+
## Rules Tree
157+
158+
Sometimes it is necessary to don't follow some rules.
159+
To avoid error reporting is is possible to:
160+
161+
- Removing rules for an entire project via configuration
162+
- Disabling rules from code, only is specific places
163+
164+
In both cases it is possible to remove or disable:
165+
166+
- a whole standard
167+
- a standard subset
168+
- a single sniff
169+
- a single rules
131170

132-
Included rules are:
133-
134-
- `WordPress.VIP.SessionVariableUsage` - Avoid usages of `$_SESSION` super global
135-
- `VIP.SessionFunctionsUsage` - Avoid usages of session-related functions
136-
- `WordPress.VIP.SuperGlobalInputUsage` - Avoid usages of sulerglobals: `$_GET`, `$_POST`, etc
137-
- `WordPress.VIP.ValidatedSanitizedInput` - Avoid non-validated/sanitized input (`$_GET`, `$_POST`, etc)
138-
- `WordPress.Security.EscapeOutput` - Verifies that all outputted strings are escaped.
139-
- `WordPress.Security.NonceVerification` - Checks that nonce verification accompanies form processing.
140-
- `WordPress.WP.AlternativeFunctions.curl` - Discourages the use of cURL functions and suggests WP alternatives.
141-
- `WordPress.WP.DiscouragedConstants` - Warns against usage of discouraged WP constants
142-
- `WordPress.WP.I18n` - Makes sure WP internationalization functions are used properly. Also checks text domain if set in `phpcs.xml`
143-
- `WordPress.Arrays.CommaAfterArrayItem` - Ensure last item of arrays have a comma
144-
- `WordPress.PHP.StrictComparisons` - Enforces Strict Comparison checks
145-
- `WordPress.PHP.StrictInArray` - Prevent calling `in_array()`, `array_search()` and `array_keys()` without `true` as the 3rd parameter
146-
- `WordPress.PHP.POSIXFunctions` - Suggest usage of PCRE functions (`preg_*`) instead of POSIX alternative
147-
- `WordPress.PHP.RestrictedPHPFunctions` - Prevent usage of `create_function`
148-
- `WordPress.PHP.DiscouragedPHPFunctions` - Discourage usage of soem PHP functions (runtime configuration, system calls)
149-
- `WordPress.PHP.DevelopmentFunctions` - Prevent usage of development PHP functions (`error_log`, `var_dump`, `var_export`, `print_r`...)
150-
151-
Any of these rules (just like the others) can be excluded in the `phpcs.xml`, using a syntax like this:
171+
The for things above are in hierarchical relationship: a _standard_ is made of one
172+
or more _subset_, each subset contains one or more _sniff_ and each sniff contains
173+
one or more rule.
174+
175+
The folder `/docs/rules-list/` of this repo contains 6 files, each of them contain
176+
the rules _tree_ for one (or few related) standard(s).
177+
178+
For example, in the file `docs/rules-list/psr.md` is is possible to read something
179+
like:
180+
181+
```
182+
- PSR1
183+
- PSR1.Classes
184+
- PSR1.Classes.ClassDeclaration
185+
- PSR1.Classes.ClassDeclaration.MultipleClasses
186+
```
187+
188+
Where:
189+
- "_PSR1_" is the standard
190+
- "_PSR1.Classes_" is the subset
191+
- "_PSR1.Classes.ClassDeclaration_" is the sniff
192+
- "_PSR1.Classes.ClassDeclaration.MultipleClasses_" is the rule
193+
194+
195+
## Remove rules via configuration file
196+
197+
Rules can be removed for the entire project by using a custom `phpcs.xml`, with
198+
a syntax like this:
152199

153200
```xml
154201
<?xml version="1.0"?>
155202
<ruleset name="MyProjectCodingStandard">
156203

157204
<rule ref="Inpsyde">
158-
<exclude name="WordPress.PHP.DevelopmentFunctions"/>
205+
<exclude name="PSR1.Classes.ClassDeclaration"/>
159206
</rule>
160207

161208
</ruleset>
162209
```
163210

211+
In the example above, the _sniff_ `PSR1.Classes.ClassDeclaration` (and all the rules
212+
it contains) has been removed.
213+
214+
Replacing `PSR1.Classes.ClassDeclaration` with just `PSR1` had been possible to
215+
remove the whole standard, while replacing it with `PSR1.Classes.ClassDeclaration.MultipleClasses`
216+
only the single rule is removed.
217+
218+
## Remove rules via code comments
219+
220+
If it is necessary to remove a rule/sniff/standard subset/standard only in
221+
specific place in the code, it is possible to use special comments that starts
222+
with:
223+
224+
```php
225+
// phpcs:disable
226+
```
227+
228+
followed by the what you want to to remove.
229+
230+
For example: `// phpcs:disable PSR1.Classes.ClassDeclaration`.
231+
232+
From the point the comment is encountered to the end of the file, the requested
233+
rule/sniff/standard subset/standard is not checked anymore.
234+
235+
To re-enable it is necessary to use a similar syntax, but this time using
236+
`phpcs:enable` instead of `phpcs:disable`.
237+
238+
It worth nothing:
239+
240+
- `phpcs:disable` and `phpcs:enable` can be used without anything else, in this
241+
case the check for *all* rules are disabled/enabled.
242+
- Disabling / enabling comments could be embedded in doc block comments at
243+
file/class/method level. For example:
244+
245+
```php
246+
class Foo
247+
{
248+
/**
249+
* @param mixed $a
250+
* @param mixed $b
251+
*
252+
* phpcs:disable NeutronStandard.Functions.TypeHint.NoArgumentType
253+
*/
254+
public function test($a, $b)
255+
{
256+
// phpcs:enable
257+
}
258+
}
259+
```
260+
261+
164262
-------------
165263

264+
166265
# IDE integration
167266

168267
## PhpStorm

docs/rules-list/custom.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Custom Rules
2+
3+
- CodingStandard
4+
- CodingStandard.CodeQuality
5+
- CodingStandard.CodeQuality.ElementNameMinimalLength
6+
- CodingStandard.CodeQuality.ElementNameMinimalLength.TooShort
7+
- CodingStandard.CodeQuality.ForbiddenPublicProperty
8+
- CodingStandard.CodeQuality.ForbiddenPublicProperty.Found
9+
- CodingStandard.CodeQuality.FunctionLength
10+
- CodingStandard.CodeQuality.FunctionLength.TooLong
11+
- CodingStandard.CodeQuality.MaxNestingLevel
12+
- CodingStandard.CodeQuality.MaxNestingLevel.TooNested
13+
- CodingStandard.CodeQuality.NoElse
14+
- CodingStandard.CodeQuality.NoElse.NoElse
15+
- CodingStandard.CodeQuality.NoSetter
16+
- CodingStandard.CodeQuality.NoSetter.NoSetter
17+
- CodingStandard.CodeQuality.PropertyPerClassLimit
18+
- CodingStandard.CodeQuality.PropertyPerClassLimit.TooMuchProperties

docs/rules-list/generic.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Generic, Squiz and PEAR Rules
2+
3+
- Generic
4+
- Generic.ControlStructures
5+
- Generic.ControlStructures.InlineControlStructure
6+
- Generic.ControlStructures.InlineControlStructure.NotAllowed
7+
- Generic.Files
8+
- Generic.Files.ByteOrderMark
9+
- Generic.Files.ByteOrderMark.Found
10+
- Generic.Files.LineEndings
11+
- Generic.Files.LineEndings.InvalidEOLChar
12+
- Generic.Files.LineLength
13+
- Generic.Functions
14+
- Generic.FunctionCallArgumentSpacing
15+
- Generic.NamingConventions
16+
- Generic.NamingConventions.UpperCaseConstantName
17+
- Generic.WhiteSpace
18+
- Generic.WhiteSpace.SuperfluousWhitespace
19+
- Generic.WhiteSpace.ScopeIndent
20+
- Generic.WhiteSpace.DisallowTabIndent
21+
- Generic.Formatting
22+
- Generic.Formatting.DisallowMultipleStatements
23+
- Generic.PHP
24+
- Generic.PHP.LowerCaseKeyword
25+
26+
- Squiz
27+
- Squiz.Classes
28+
- Squiz.Classes.ValidClassName
29+
- Squiz.ControlStructures
30+
- Squiz.ControlStructures.ControlSignature
31+
- Squiz.ControlStructures.ForEachLoopDeclaration
32+
- Squiz.ControlStructures.ForLoopDeclaration
33+
- Squiz.ControlStructures.LowercaseDeclaration
34+
- Squiz.ControlStructures.InlineControlStructure
35+
- Squiz.Functions
36+
- Squiz.Functions.FunctionDeclaration
37+
- Squiz.Functions.LowercaseFunctionKeywords
38+
- Squiz.Functions.FunctionDeclarationArgumentSpacing
39+
- Squiz.Functions.MultiLineFunctionDeclaration
40+
- Squiz.Scope
41+
- Squiz.Scope.MethodScope
42+
- Squiz.PHP
43+
- Squiz.PHP.Eval
44+
- Squiz.PHP.Eval.Discouraged
45+
- Squiz.PHP.CommentedOutCode
46+
- Squiz.PHP.CommentedOutCode.Found
47+
- Squiz.WhiteSpace
48+
- Squiz.WhiteSpace.ScopeKeywordSpacing
49+
- Squiz.WhiteSpace.ControlStructureSpacing
50+
- Squiz.WhiteSpace.ScopeClosingBrace
51+
52+
- PEAR
53+
- PEAR.Functions
54+
- PEAR.Functions.ValidDefaultValue

docs/rules-list/neutron-standard.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Neutron Standard Rules
2+
3+
- NeutronStandard
4+
- NeutronStandard.Arrays
5+
- NeutronStandard.Arrays.DisallowLongformArray
6+
- NeutronStandard.Arrays.DisallowLongformArray.LongformArray
7+
- NeutronStandard.Conditions
8+
- NeutronStandard.Conditions.DisallowConditionAssignWithoutConditional
9+
- NeutronStandard.Conditions.DisallowConditionAssignWithoutConditional.ConditionAssignWithoutConditional
10+
- NeutronStandard.Constants
11+
- NeutronStandard.Constants.DisallowDefine
12+
- NeutronStandard.Constants.DisallowDefine.Define
13+
- NeutronStandard.Extract
14+
- NeutronStandard.Extract.DisallowExtract
15+
- NeutronStandard.Extract.DisallowExtract.Extract
16+
- NeutronStandard.Functions
17+
- NeutronStandard.Functions.DisallowCallUserFunc
18+
- NeutronStandard.Functions.DisallowCallUserFunc.CallUserFunc
19+
- NeutronStandard.Functions.TypeHint
20+
- NeutronStandard.Functions.TypeHint.NoArgumentType
21+
- NeutronStandard.Functions.TypeHint.UnusedReturnType
22+
- NeutronStandard.Functions.TypeHint.IncorrectVoidReturnType
23+
- NeutronStandard.Globals
24+
- NeutronStandard.Globals.DisallowGlobalFunctions
25+
- NeutronStandard.Globals.DisallowGlobalFunctions.GlobalFunctions
26+
- NeutronStandard.MagicMethods
27+
- NeutronStandard.MagicMethods.DisallowMagicGet
28+
- NeutronStandard.MagicMethods.DisallowMagicGet.MagicGet
29+
- NeutronStandard.MagicMethods.DisallowMagicSerialize
30+
- NeutronStandard.MagicMethods.DisallowMagicSerialize.MagicSerialize
31+
- NeutronStandard.MagicMethods.DisallowMagicSet
32+
- NeutronStandard.MagicMethods.DisallowMagicSet.MagicSet
33+
- NeutronStandard.MagicMethods.RiskyMagicMethod
34+
- NeutronStandard.MagicMethods.RiskyMagicMethod.RiskyMagicMethod
35+
- NeutronStandard.StrictTypes
36+
- NeutronStandard.StrictTypes.RequireStrictTypes
37+
- NeutronStandard.StrictTypes.RequireStrictTypes.StrictTypes
38+
- NeutronStandard.Whitespace
39+
- NeutronStandard.Whitespace.DisallowMultipleNewlines
40+
- NeutronStandard.Whitespace.DisallowMultipleNewlines.MultipleNewlines

0 commit comments

Comments
 (0)