@@ -12,7 +12,7 @@ It means they can be installed by adding the entry to composer.json `require-dev
12
12
``` json
13
13
{
14
14
"require-dev" : {
15
- "inpsyde/php-coding-standards" : " ^0.9 "
15
+ "inpsyde/php-coding-standards" : " ~0.10.0 "
16
16
}
17
17
}
18
18
```
@@ -114,6 +114,15 @@ See https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards.
114
114
115
115
The tree of used rules are listed in the ` /docs/rules-list/wordpress.md ` file in this repo.
116
116
117
+ ## PHPCompatibility
118
+
119
+ See https://github.com/wimg/PHPCompatibility .
120
+
121
+ It allows to analyse code for compatibility with higher and lower versions of PHP.
122
+ The default target version is PHP 7.0+.
123
+
124
+ Target version can be changed via custom ` phpcs.xml ` .
125
+
117
126
118
127
## Generic Rules
119
128
@@ -127,76 +136,28 @@ The tree of used rules are listed in the `/docs/rules-list/generic.md` file in t
127
136
128
137
## Custom Rules
129
138
130
- Few custom rules are also in use.
131
- Customs rules are:
132
-
133
- - Enforce argument type declaration, with few exception (e.g. hook callbacks or ` ArrayAccess ` methods)
134
- - Ensure that any assignment inside conditions in wrapped in parenthesis
135
- - Disallow short open PHP tag
136
- - Use minimum 3 chars for names (with a few exclusions)
137
- - No public class properties
138
- - Max 50 lines per function/method, excluding blank lines and comments-only lines.
139
- - Ensure that actions callbacks do not return anything, while filter callbacks return something.
140
- - Max 100 chars per line, excluding leading indent size and long string inWP translation functions
141
- - Discourage usage of getters and setters.
142
- - Discourage usage of ` else ` .
143
- - Discourage usage of ` define ` where ` const ` is preferable.
144
- - Discourage usage of more than 10 properties per class.
145
- - Enforce return type declaration, with few exceptions (e.g. hook callbacks or ` ArrayAccess ` methods)
146
- - Check PSR-4 compliance
147
-
148
- The tree of used rules are listed in the ` /docs/rules-list/custom.md ` file in this repo.
149
-
150
- ### Notes & Configuration
151
-
152
- #### Skip ` Inpsyde.CodeQuality.ReturnTypeDeclaration.NoReturnType ` via doc bloc
153
-
154
- As of v0.9, when there's no return type declared for a function, but it has a docbloc like:
155
- ` @return {$type}|null ` and the function _ actually_ contains both ` null ` and not-null return
156
- points ** no** warning is shown.
157
- However, if min PHP version is set to 7.1 via php-compatibility ` testVersion ` config, the warning
158
- ** is** shown, because in PHP 7.1 there's the availability for nullable return types.
159
- Also note that the warning ** is** shown in case:
160
- - the ` @return ` docbloc declares more than one not-null types, e.g. ` @return Foo|Bar|null `
161
- - the ` @return ` docbloc types contains "mixed", e.g. ` @return mixed|null ` .
162
-
163
-
164
- #### PSR-4 Configuration
165
- ` Inpsyde.CodeQuality.Psr4 ` rule needs some configuration to check namespace and
166
- class file paths.
167
- Without configuration the only thing the sniff does is to check that class name and file name match.
168
- The needed configuration mimics the PSR-4 configuration in ` composer.json ` .
169
- Assuming a ` composer.json ` like:
170
- ``` json
171
- {
172
- "autoload" : {
173
- "psr-4" : {
174
- "Inpsyde\\ Foo\\ " : " src/" ,
175
- "Inpsyde\\ Foo\\ Bar\\ Baz\\ " : " baz/"
176
- }
177
- }
178
- }
179
- ```
180
- the rule configuration should be:
181
- ``` xml
182
- <rule ref =" Inpsyde.CodeQuality.Psr4" >
183
- <properties >
184
- <property name =" psr4" type =" array" value =" Inpsyde\Foo=>src,Inpsyde\Foo\Bar\Baz=>baz" />
185
- </properties >
186
- </rule >
187
- ```
188
- Please note that when a PSR-4 configuration is given, * all* autoloadable entities (classes/interfaces/trait)
189
- are checked to be compliant.
190
- If there are entities in the sniffer target paths that are not PSR-4 compliant (e.g. loaded via classmap
191
- or not autoloaded at all) those should be excluded via ` exclude ` property, e.g.
192
- ``` xml
193
- <rule ref =" Inpsyde.CodeQuality.Psr4" >
194
- <properties >
195
- <property name =" psr4" type =" array" value =" Inpsyde\SomePlugin=>src" />
196
- <property name =" exclude" type =" array" value =" Inpsyde\ExcludeThis,Inpsyde\AndThis" />
197
- </properties >
198
- </rule >
199
- ```
139
+ Some custom rules are also in use. They are:
140
+
141
+ | Sniff name | Description | Has Config | Has Notes |
142
+ | :-----------| :------------| :----------:| :---------:|
143
+ | ` ArgumentTypeDeclarationSniff ` | Enforce argument type declaration, with few exception (e.g. hook callbacks or ` ArrayAccess ` methods)|||
144
+ | ` AssignmentInsideConditionSniff ` | Ensure that any assignment inside conditions in wrapped in parenthesis|||
145
+ | ` DisallowShortOpenTagSniff ` | Disallow short open PHP tag (short echo tag allowed).|||
146
+ | ` ElementNameMinimalLengthSniff ` | Use minimum 3 chars for names (with a few exclusions)| ✓||
147
+ | ` ForbiddenPublicPropertySniff ` | No public class properties|||
148
+ | ` FunctionLengthSniff ` | Max 50 lines per function/method, excluding blank lines and comments-only lines.| ✓||
149
+ | ` HookClosureReturnSniff ` | Ensure that actions callbacks do not return anything, while filter callbacks return something.|||
150
+ | ` LineLengthSniff ` | Max 100 chars per line, excluding leading indent space and long string in WP translation functions| ✓||
151
+ | ` NoAccessorsSniff ` | Discourage usage of getters and setters.|||
152
+ | ` NoElseSniff ` | Discourage usage of ` else ` .|||
153
+ | ` NoTopLevelDefineSniff ` | Discourage usage of ` define ` where ` const ` is preferable.|||
154
+ | ` PropertyPerClassLimitSniff ` | Discourage usage of more than 10 properties per class.| ✓||
155
+ | ` Psr4Sniff ` | Check PSR-4 compliance| ✓||
156
+ | ` ReturnTypeDeclarationSniff ` | Enforce return type declaration, with few exceptions (e.g. hook callbacks or ` ArrayAccess ` methods)|| ✓|
157
+
158
+ For ** notes and configuration** see ` /docs/rules-list/inpsyde-rules-configuration.md ` file in this repo.
159
+
160
+ The tree of rules are listed in the ` /docs/rules-list/custom.md ` file in this repo.
200
161
201
162
-------------
202
163
0 commit comments