Skip to content

Commit 85e25cf

Browse files
committed
Update readme file
1 parent 9598a84 commit 85e25cf

File tree

1 file changed

+82
-102
lines changed

1 file changed

+82
-102
lines changed

README.md

Lines changed: 82 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ the coding standards can be checked via:
1515
vendor/bin/phpcs --standard="Inpsyde" <path>
1616
```
1717

18-
Where `<path>` is at least one file or directory to check, e.g.:
18+
Here, `<path>` is at least one file or directory to check, for example:
1919

2020
```shell
2121
vendor/bin/phpcs --standard="Inpsyde" ./src/ ./my-plugin.php
@@ -30,7 +30,7 @@ vendor/bin/phpcs --help
3030

3131
## Configuration File
3232

33-
A `phpcs.xml.dist` can be used to avoid passing many arguments via command line.
33+
A `phpcs.xml.dist` file can be used to avoid passing many arguments via the command line.
3434
For example:
3535

3636
```xml
@@ -47,11 +47,11 @@ For example:
4747

4848
<config name="testVersion" value="7.4-"/>
4949
<config name="text_domain" value="my-project"/>
50-
50+
5151
<rule ref="Inpsyde">
52-
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize" />
52+
<exclude name="WordPress.PHP.DiscouragedPHPFunctions.serialize_serialize"/>
5353
</rule>
54-
54+
5555
<rule ref="Inpsyde.CodeQuality.Psr4">
5656
<properties>
5757
<property
@@ -67,55 +67,57 @@ For example:
6767
</ruleset>
6868
```
6969

70-
Such a configuration allows to run the code style check with only:
70+
Such a configuration allows to run the code style check like so:
7171

7272
```shell
7373
vendor/bin/phpcs
7474
```
7575

76-
Moreover, thanks to the `text_domain` setting, Code Sniffer will also check that all WP
76+
Moreover, thanks to the `text_domain` setting, PHP_CodeSniffer will also check that all WordPress
7777
internationalization functions are called with the proper text domain.
7878

7979
---
8080

8181
# Included rules
8282

83-
For the detailed lists of included rules refers to [`ruleset.xml](./Inpsyde/ruleset.xml).
83+
For the detailed lists of included rules, refer to [`ruleset.xml`](./Inpsyde/ruleset.xml).
8484

8585
## PSR-1, PSR-2, PSR-12
8686

87-
See https://www.php-fig.org/psr/psr-1, https://www.php-fig.org/psr/psr-2,
88-
https://www.php-fig.org/psr/psr-12
87+
For more information about included rules from PHP Standards Recommendations (PSR), refer to the
88+
official documentation:
89+
90+
- [PSR-1](https://www.php-fig.org/psr/psr-1)
91+
- [PSR-2](https://www.php-fig.org/psr/psr-2)
92+
- [PSR-12](https://www.php-fig.org/psr/psr-12)
8993

90-
## WordPress Coding Standard
94+
## WordPress Coding Standards
9195

92-
To ensure code quality, and compatibility with wp.com VIP, several WordPress Coding Standard rules
93-
have been"cherry-picked" from
94-
[WP coding standards](https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards) and
95-
[VIP coding standard](https://github.com/Automattic/VIP-Coding-Standards/)
96+
To ensure code quality, and compatibility with WordPress VIP, some rules have been included from:
97+
98+
- [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
99+
- [VIP Coding Standards](https://github.com/Automattic/VIP-Coding-Standards)
96100

97101
## Slevomat
98102

99-
A few rules are cherry-picked from ["Slevomat" coding standard](https://github.com/slevomat/coding-standard).
103+
A few rules have been included from the [Slevomat Coding Standard](https://github.com/slevomat/coding-standard).
100104

101105
## PHPCompatibility
102106

103-
See https://github.com/wimg/PHPCompatibility.
104-
105-
It allows to analyse code for compatibility with higher and lower versions of PHP.
106-
The default target version is PHP 7.0+.
107+
For PHP cross-version compatibility checks, the full [PHP Compatibility Coding Standard for PHP CodeSniffer](https://github.com/PHPCompatibility/PHPCompatibility)
108+
standard has been included.
107109

108-
Target version can be changed via custom `phpcs.xml`.
110+
The target PHP version (range) can be changed via a [custom `phpcs.xml` file](https://github.com/PHPCompatibility/PHPCompatibility/blob/9.3.5/README.md#using-a-custom-ruleset).
109111

110112
## Generic Rules
111113

112-
Some rules are also included from PHPCS itself and [PHPCS Extra](https://github.com/PHPCSStandards/PHPCSExtra).
114+
Some rules are also included from PHP_CodeSniffer itself, as well as [PHPCSExtra](https://github.com/PHPCSStandards/PHPCSExtra).
113115

114116
## Custom Rules
115117

116-
Some custom rules are also in use. They are:
118+
The following custom rules are in use:
117119

118-
| Sniff name | Description | Has Config | Auto-Fixable |
120+
| Sniff Name | Description | Has Config | Auto-Fixable |
119121
|:---------------------------|:-----------------------------------------------------------------------------------------------|:----------:|:------------:|
120122
| `ArgumentTypeDeclaration` | Enforce argument type declaration. | | |
121123
| `DisableCallUserFunc` | Disable usage of `call_user_func`. | | |
@@ -140,7 +142,8 @@ Some custom rules are also in use. They are:
140142
| `StaticClosure` | Points closures that can be `static`. | ||
141143
| `VariablesName` | Check variable (and properties) names || |
142144

143-
For **notes and configuration** see [`/inpsyde-custom-sniffs.md`](/inpsyde-custom-sniffs.md) file in this repo.
145+
For **notes and configuration**, refer to the [`inpsyde-custom-sniffs.md`](/inpsyde-custom-sniffs.md)
146+
file in this repository.
144147

145148
---
146149

@@ -153,12 +156,12 @@ The recommended way to use the `InpsydeTemplates` ruleset is as follows:
153156

154157
```xml
155158
<ruleset>
156-
<file>./src/</file>
157-
<file>./tests</file>
159+
<file>./src</file>
158160
<file>./templates</file>
161+
<file>./tests</file>
159162
<file>./views</file>
160163

161-
<rule ref="Inpsyde" />
164+
<rule ref="Inpsyde"/>
162165

163166
<rule ref="InpsydeTemplates">
164167
<include-pattern>*/templates/*</include-pattern>
@@ -167,137 +170,114 @@ The recommended way to use the `InpsydeTemplates` ruleset is as follows:
167170
</ruleset>
168171
```
169172

170-
The following templates-specific rules are available:
173+
The following template-specific rules are available:
171174

172-
| Sniff name | Description | Has Config | Auto-Fixable |
175+
| Sniff Name | Description | Has Config | Auto-Fixable |
173176
|:--------------------|:--------------------------------------------------|:----------:|:------------:|
174177
| `TrailingSemicolon` | Remove trailing semicolon before closing PHP tag. | ||
175178

176179
# Removing or Disabling Rules
177180

178181
## Rules Tree
179182

180-
Sometimes it is necessary to don't follow some rules. To avoid error reporting it is possible to:
183+
Sometimes it is necessary not to follow some rules. To avoid error reporting, it is possible to:
181184

182-
- Removing rules for an entire project via configuration
183-
- Disabling rules from code, only is specific places
185+
- remove rules for an entire project via configuration;
186+
- disable rules from code, only is specific places.
184187

185-
In both cases it is possible to remove or disable:
188+
In both cases, it is possible to remove or disable:
186189

187-
- a whole standard
188-
- a standard subset
189-
- a single sniff
190-
- a single rules
190+
- a complete standard;
191+
- a standard subset;
192+
- a single sniff;
193+
- a single rule.
191194

192-
The for things above are in hierarchical relationship: a _standard_ is made of one or more _subset_,
193-
each subset contains one or more _sniff_ and each sniff contains one or more rule.
195+
These things are in a hierarchical relationship: _standards_ are made of one or more _subsets_,
196+
which contain one or more _sniffs_, which in turn contain one or more _rules_.
194197

195-
## Remove rules via configuration file
198+
## Removing Rules via Configuration File
196199

197-
Rules can be removed for the entire project by using a custom `phpcs.xml`, with a syntax like this:
200+
Rules can be removed for the entire project by using a custom `phpcs.xml` file, like this:
198201

199202
```xml
200203
<?xml version="1.0"?>
201204
<ruleset name="MyProjectCodingStandard">
202205

203-
<rule ref="Inpsyde">
204-
<exclude name="PSR1.Classes.ClassDeclaration"/>
205-
</rule>
206+
<rule ref="Inpsyde">
207+
<exclude name="PSR1.Classes.ClassDeclaration"/>
208+
</rule>
206209

207210
</ruleset>
208211
```
209212

210-
In the example above, the _sniff_ `PSR1.Classes.ClassDeclaration` (and all the rules it contains)
213+
In the example above, the `PSR1.Classes.ClassDeclaration` sniff (and all the rules it contains)
211214
has been removed.
212215

213-
Replacing `PSR1.Classes.ClassDeclaration` with just `PSR1` had been possible to
214-
remove the whole standard, while replacing it with `PSR1.Classes.ClassDeclaration.MultipleClasses`
215-
only the single rule is removed.
216-
217-
## Remove rules via code comments
218-
219-
If it is necessary to remove a rule/sniff/standard subset/standard only in specific place in the
220-
code, it is possible to use special comments that starts with `// phpcs:disable` followed by the
221-
name of the sniff to disable.
222-
223-
For example: `// phpcs:disable PSR1.Classes.ClassDeclaration`.
216+
By using `PSR1` instead of `PSR1.Classes.ClassDeclaration`, one would remove the entire `PSR1`
217+
standard, whereas using `PSR1.Classes.ClassDeclaration.MultipleClasses` would remove this one rule
218+
only, but no other rules in the `PSR1.Classes.ClassDeclaration` sniff.
224219

225-
From the point the comment is encountered to the end of the file, the requested rule/sniff/standard
226-
subset/standard is not checked anymore.
220+
## Removing Rules via Code Comments
227221

228-
To re-enable it is necessary to use a similar syntax, but this time using `phpcs:enable` instead of
229-
`phpcs:disable`.
222+
Removing a rule/sniff/subset/standard only for a specific file or a part of it can be done by using
223+
special `phpcs` annotations/comments, for example, `// phpcs:disable` followed by an optional name
224+
of a standard/subset/sniff/rule. Like so:
230225

231-
It is worth noting:
232-
233-
- `phpcs:disable` and `phpcs:enable` can be used without specifying the rule name, in this case the
234-
check for *all* rules are disabled/enabled.
235-
- Disabling / enabling comments could be embedded in doc block comments at file/class/method level.
236-
For example:
237-
238226
```php
239-
class Foo
240-
{
241-
/**
242-
* @param mixed $a
243-
* @param mixed $b
244-
*
245-
* phpcs:disable NeutronStandard.Functions.TypeHint.NoArgumentType
246-
*/
247-
public function test($a, $b)
248-
{
249-
// phpcs:enable
250-
}
251-
}
227+
// phpcs:disable PSR1.Classes.ClassDeclaration
252228
```
253229

230+
For more information about ignoring files, please refer to the official [PHP_CodeSniffer Wiki](https://github.com/PHPCSStandards/PHP_CodeSniffer/wiki/Advanced-Usage#ignoring-parts-of-a-file).
231+
254232
---
255233

256-
# IDE integration
234+
# IDE Integration
257235

258236
## PhpStorm
259237

260-
After having installed the package as explained above in the _"Installation"_ section,
261-
open PhpStorm settings, and navigate to
238+
After installing the package as explained above, open PhpStorm settings, and navigate to
262239

263240
`Language & Frameworks` -> `PHP` -> `Quality Tools` -> `PHP_CodeSniffer`
264241

265242
Choose _"Local"_ in the _"Configuration"_ dropdown.
266243

267-
Click the _"..."_ button next to the dropdown, it will show a dialog
268-
where you need to specify the path for the Code Sniffer executable.
244+
Click the _"..."_ button next to the dropdown. It will show a dialog where you need to specify
245+
the path for the PHP_CodeSniffer executable.
269246

270-
Open the file selection dialog, navigate to `vendor/bin/` in your project and select `phpcs`
271-
(`phpcs.bat` on Windows).
247+
Open the file selection dialog, navigate to `vendor/bin/` in your project, and select `phpcs`.
248+
On Windows, choose `phpcs.bat`.
272249

273-
Click the _"Validate"_ button next to the path input field, if everything is fine
274-
a success message will be shown at the bottom of the window.
250+
Click the _"Validate"_ button next to the path input field. If everything is working fine, a
251+
success message will be shown at the bottom of the window.
275252

276-
Navigate PhpStorm settings to:
253+
Still in the PhpStorm settings, navigate to:
277254

278255
`Editor` -> `Inspections`
279256

280-
Type `codesniffer` in the search field before the list of inspections,
281-
select `PHP` -> `Quality Tools` -> `PHP_CodeSniffer validation` and enable it using the checkbox in
282-
the list, press _"Apply"_.
257+
Type `codesniffer` in the search field before the list of inspections, then select:
258+
259+
`PHP` -> `Quality Tools` -> `PHP_CodeSniffer validation`
260+
261+
Enable it using the checkbox in the list, press _"Apply"_.
283262

284-
Select _"PHP_CodeSniffer validation"_, press the refresh icon next to the _"Coding standard"_
285-
dropdown on the right and choose `Inpsyde`.
263+
Select _"PHP_CodeSniffer validation"_, click the refresh icon next to the _"Coding standard"_
264+
dropdown on the right, and choose `Inpsyde`.
286265

287-
If you do not see `Inpsyde` here, you may need to specify `phpcs.xml` file by selecting _"Custom"_
288-
as standard and using the _"..."_ button next to the dropdown.
266+
If you don't see `Inpsyde` here, you may need to specify the `phpcs.xml` file by selecting
267+
_"Custom"_ as standard and then use the _"..."_ button next to the dropdown.
289268

290-
Now PhpStorm integration is complete, and errors in the code style will be shown in the IDE editor
291-
allowing to detect them without running any commands at all.
269+
Once the PhpStorm integration is complete, warnings and errors in your code will automatically be
270+
shown in your IDE editor.
292271

293272
---
294273

295274
# Installation
296275

297-
Via Composer, require as dev-dependency:
276+
Via Composer, require as development dependency:
298277

299278
```shell
300279
composer require "inpsyde/php-coding-standards:^2@dev" --dev
301280
```
302281

303-
_(the `@dev` can be removed as soon as the stable 2.0.0 will be released, or if root package minimum stability is "dev")._
282+
_(Please note that `@dev` can be removed as soon as a stable 2.0.0 version has been released, or if
283+
your root package minimum stability is `dev`)._

0 commit comments

Comments
 (0)