Skip to content

Commit 8975242

Browse files
committed
Update new "About Standards" page
* Syntax highlighting PHP samples. * Make it clearer which examples are invalid. * Spelling/grammar fixes.
1 parent 10c3f28 commit 8975242

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

wiki/About-Standards-for-PHP_CodeSniffer.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You may also find the [Customisable Sniff Properties](https://github.com/PHPCSSt
4848
In the context of PHP_CodeSniffer, a _"standard"_ is a predefined collection of rules for code to follow.
4949
Examples of standards are: PSR2 and PSR12, but a standard can also be eco-system specific, such as a Joomla or Doctrine standard, company specific or specific to a group of (related) projects.
5050

51-
PHP_CodeSniffer has a number of build-in standards. However, if you want to define your own standard, you can.
51+
PHP_CodeSniffer has a number of built-in standards. However, if you want to define your own standard, you can.
5252
In terms of PHP_CodeSniffer, this is regarded as an _"external standard"_ and the path to the standard can be registered with PHP_CodeSniffer using the `--config-set installed_paths path/to/standard` command.
5353

5454
A standard _may_ contain sniffs, but it doesn't have to. More about this below.
@@ -100,7 +100,7 @@ As mentioned before, have a look at the [Annotated ruleset](https://github.com/P
100100

101101
## Creating new rules
102102

103-
There may be rules you want to enforce for which you cannot find an existing sniff, either in the PHP_CodeSniffer build-in standards or in any of the available generic external standards.
103+
There may be rules you want to enforce for which you cannot find an existing sniff, either in the PHP_CodeSniffer built-in standards or in any of the available generic external standards.
104104

105105
In that case, you can write your own sniff to enforce that rule.
106106

@@ -133,7 +133,7 @@ The directory structure MUST be as follows:
133133

134134
#### 2. Sniff file name
135135

136-
All sniff files MUST end on `Sniff.php` and be located within a `[CategoryName]` directory.
136+
All sniff file names MUST end with `Sniff.php` and be located within a `[CategoryName]` directory.
137137

138138
All sniffs MUST have a name, so a sniff class called just and only `Sniff` is not allowed.
139139

@@ -144,7 +144,7 @@ Both the sniff name and the category name MUST be valid symbol names in PHP.
144144

145145
The namespace and class name MUST follow [PSR-4](https://www.php-fig.org/psr/psr-4/).
146146

147-
This means that - taking the example directory structure above in to account - the namespace name MUST end on `[StandardName]\Sniffs\[CategoryName]` and the class name MUST be exactly the same as the file name (minus the `.php` file extension).
147+
This means that - taking the example directory structure above in to account - the namespace name MUST end with `[StandardName]\Sniffs\[CategoryName]` and the class name MUST be exactly the same as the file name (minus the `.php` file extension).
148148

149149
> [!NOTE]
150150
> As long as an external standard is registered with PHP_CodeSniffer via `installed_paths` and the standard follows the directory layout and naming conventions, PHP_CodeSniffer can, and will, automatically handle the sniff autoloading.
@@ -156,7 +156,7 @@ This means that - taking the example directory structure above in to account - t
156156

157157

158158
##### Valid:
159-
```
159+
```php
160160
<?php
161161
// File: MyStandard/Sniffs/Operators/OperatorSpacingSniff.php
162162

@@ -169,7 +169,7 @@ class OperatorSpacingSniff implements Sniff {...}
169169
```
170170

171171
Prefixing the namespace is allowed:
172-
```
172+
```php
173173
<?php
174174
// File: MyStandard/Sniffs/Operators/OperatorSpacingSniff.php
175175

@@ -190,7 +190,7 @@ Be sure to inform PHP_CodeSniffer about the namespace prefix by annotating it in
190190
```
191191

192192
Nesting the standard directory deeper inside a project is allowed:
193-
```
193+
```php
194194
<?php
195195
// File: src/Tools/PHPCS/MyStandard/Sniffs/Operators/OperatorSpacingSniff.php
196196

@@ -208,8 +208,8 @@ Also make sure that the `installed_paths` configuration option is set correctly
208208

209209
##### Invalid:
210210

211-
Sniff name not ending on `Sniff`:
212-
```
211+
:x: Sniff name not ending on `Sniff`:
212+
```php
213213
<?php
214214
// File: MyStandard/Sniffs/Operators/OperatorSpacing.php
215215

@@ -221,8 +221,8 @@ use PHP_CodeSniffer\Sniffs\Sniff;
221221
class OperatorSpacing implements Sniff {...}
222222
```
223223

224-
Sniff not placed in a (sub-)directory under a `Sniffs` directory:
225-
```
224+
:x: Sniff not placed in a (sub-)directory under a `Sniffs` directory:
225+
```php
226226
<?php
227227
// File: MyStandard/Operators/OperatorSpacing.php
228228

@@ -234,8 +234,8 @@ use PHP_CodeSniffer\Sniffs\Sniff;
234234
class OperatorSpacingSniff implements Sniff {...}
235235
```
236236

237-
Not following the required directory structure (missing `[CategoryName]` subdirectory):
238-
```
237+
:x: Not following the required directory structure (missing `[CategoryName]` subdirectory):
238+
```php
239239
<?php
240240
// File: MyStandard/Sniffs/OperatorSpacingSniff.php
241241

@@ -247,8 +247,8 @@ use PHP_CodeSniffer\Sniffs\Sniff;
247247
class OperatorSpacingSniff implements Sniff {...}
248248
```
249249

250-
Not following the required directory structure (missing `[StandardName]` top-level directory):
251-
```
250+
:x: Not following the required directory structure (missing `[StandardName]` top-level directory):
251+
```php
252252
<?php
253253
// File: src/Sniffs/Operators/OperatorSpacingSniff.php
254254

0 commit comments

Comments
 (0)