Skip to content

Commit fdfc524

Browse files
authored
Merge pull request #148 from PHPCSStandards/docs/enhance-documentation-texts
Docs: enhance documentation
2 parents 2353f96 + 1ab8689 commit fdfc524

22 files changed

+345
-158
lines changed

PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ abstract class AbstractArrayDeclarationSniff implements Sniff
6969
*
7070
* The array index is 1-based and contains the following information on each array item:
7171
* - 'start' : The stack pointer to the first token in the array item.
72-
* - 'end' : The stack pointer to the first token in the array item.
72+
* - 'end' : The stack pointer to the last token in the array item.
7373
* - 'raw' : A string with the contents of all tokens between `start` and `end`.
7474
* - 'clean' : Same as `raw`, but all comment tokens have been stripped out.
7575
*
@@ -100,6 +100,8 @@ abstract class AbstractArrayDeclarationSniff implements Sniff
100100
/**
101101
* List of tokens which can safely be used with an eval() expression.
102102
*
103+
* This list gets enhanced with additional token groups in the constructor.
104+
*
103105
* @since 1.0.0
104106
*
105107
* @var array
@@ -203,7 +205,19 @@ final public function process(File $phpcsFile, $stackPtr)
203205
/**
204206
* Process every part of the array declaration.
205207
*
206-
* This contains the default logic for the sniff, but can be overloaded in a concrete child class
208+
* Controller which calls the individual `process...()` methods for each part of the array.
209+
*
210+
* The method starts by calling the {@see AbstractArrayDeclarationSniff::processOpenClose()} method
211+
* and subsequently calls the following methods for each array item:
212+
*
213+
* Unkeyed arrays | Keyed arrays
214+
* -------------- | ------------
215+
* processNoKey() | processKey()
216+
* - | processArrow()
217+
* processValue() | processValue()
218+
* processComma() | processComma()
219+
*
220+
* This is the default logic for the sniff, but can be overloaded in a concrete child class
207221
* if needed.
208222
*
209223
* @since 1.0.0
@@ -265,7 +279,7 @@ public function processArray(File $phpcsFile)
265279
/**
266280
* Process the array opener and closer.
267281
*
268-
* Optional method to be implemented in concrete child classes.
282+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
269283
*
270284
* @since 1.0.0
271285
*
@@ -277,6 +291,8 @@ public function processArray(File $phpcsFile)
277291
* @param int $closePtr The position of the array closer token in the token stack.
278292
*
279293
* @return true|void Returning `true` will short-circuit the sniff and stop processing.
294+
* In effect, this means that the sniff will not examine the individual
295+
* array items if `true` is returned.
280296
*/
281297
public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
282298
{
@@ -285,10 +301,10 @@ public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
285301
/**
286302
* Process the tokens in an array key.
287303
*
288-
* Optional method to be implemented in concrete child classes.
304+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
289305
*
290-
* The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to
291-
* allow examining all tokens in an array key.
306+
* Note: The `$startPtr` and `$endPtr` do not discount whitespace or comments, but are all inclusive
307+
* to allow for examining all tokens in an array key.
292308
*
293309
* @since 1.0.0
294310
*
@@ -306,6 +322,8 @@ public function processOpenClose(File $phpcsFile, $openPtr, $closePtr)
306322
* 1-based, i.e. the first item is item 1, the second 2 etc.
307323
*
308324
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
325+
* In effect, this means that the sniff will not examine the double arrow, the array
326+
* value or comma for this array item and will not process any array items after this one.
309327
*/
310328
public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
311329
{
@@ -314,12 +332,17 @@ public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
314332
/**
315333
* Process an array item without an array key.
316334
*
317-
* Optional method to be implemented in concrete child classes.
335+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
336+
*
337+
* Note: This method is _not_ intended for processing the array _value_. Use the
338+
* {@see AbstractArrayDeclarationSniff::processValue()} method to implement processing of the array value.
318339
*
319340
* @since 1.0.0
320341
*
321342
* @codeCoverageIgnore
322343
*
344+
* @see \PHPCSUtils\AbstractSniffs\AbstractArrayDeclarationSniff::processValue() Method to process the array value.
345+
*
323346
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the
324347
* token was found.
325348
* @param int $startPtr The stack pointer to the first token in the array item,
@@ -329,6 +352,8 @@ public function processKey(File $phpcsFile, $startPtr, $endPtr, $itemNr)
329352
* 1-based, i.e. the first item is item 1, the second 2 etc.
330353
*
331354
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
355+
* In effect, this means that the sniff will not examine the array value or
356+
* comma for this array item and will not process any array items after this one.
332357
*/
333358
public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
334359
{
@@ -337,7 +362,7 @@ public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
337362
/**
338363
* Process the double arrow.
339364
*
340-
* Optional method to be implemented in concrete child classes.
365+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
341366
*
342367
* @since 1.0.0
343368
*
@@ -350,6 +375,8 @@ public function processNoKey(File $phpcsFile, $startPtr, $itemNr)
350375
* 1-based, i.e. the first item is item 1, the second 2 etc.
351376
*
352377
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
378+
* In effect, this means that the sniff will not examine the array value or
379+
* comma for this array item and will not process any array items after this one.
353380
*/
354381
public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
355382
{
@@ -358,10 +385,10 @@ public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
358385
/**
359386
* Process the tokens in an array value.
360387
*
361-
* Optional method to be implemented in concrete child classes.
388+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
362389
*
363-
* The $startPtr and $endPtr do not discount whitespace or comments, but are all inclusive to
364-
* allow examining all tokens in an array value.
390+
* Note: The `$startPtr` and `$endPtr` do not discount whitespace or comments, but are all inclusive
391+
* to allow for examining all tokens in an array value.
365392
*
366393
* @since 1.0.0
367394
*
@@ -377,6 +404,8 @@ public function processArrow(File $phpcsFile, $arrowPtr, $itemNr)
377404
* 1-based, i.e. the first item is item 1, the second 2 etc.
378405
*
379406
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
407+
* In effect, this means that the sniff will not examine the comma for this
408+
* array item and will not process any array items after this one.
380409
*/
381410
public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
382411
{
@@ -385,7 +414,7 @@ public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
385414
/**
386415
* Process the comma after an array item.
387416
*
388-
* Optional method to be implemented in concrete child classes.
417+
* Optional method to be implemented in concrete child classes. By default, this method does nothing.
389418
*
390419
* @since 1.0.0
391420
*
@@ -398,6 +427,8 @@ public function processValue(File $phpcsFile, $startPtr, $endPtr, $itemNr)
398427
* 1-based, i.e. the first item is item 1, the second 2 etc.
399428
*
400429
* @return true|void Returning `true` will short-circuit the array item loop and stop processing.
430+
* In effect, this means that the sniff will not process any array items
431+
* after this one.
401432
*/
402433
public function processComma(File $phpcsFile, $commaPtr, $itemNr)
403434
{
@@ -406,7 +437,8 @@ public function processComma(File $phpcsFile, $commaPtr, $itemNr)
406437
/**
407438
* Determine what the actual array key would be.
408439
*
409-
* Optional helper function for processsing array keys in the processKey() function.
440+
* Helper function for processsing array keys in the processKey() function.
441+
* Using this method is up to the sniff implementation in the child class.
410442
*
411443
* @since 1.0.0
412444
*

PHPCSUtils/BackCompat/BCFile.php

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
* array return type declarations.
6464
* - Typed properties were not recognized prior to PHPCS 3.5.0, including the
6565
* `?` nullability token not being converted to `T_NULLABLE`.
66-
* - Arrow functions were not recognized properly until PHPCS 3.5.3.
66+
* - Arrow functions were not recognized properly until PHPCS 3.5.3/4.
6767
* - General PHP cross-version incompatibilities.
6868
*
6969
* Most functions in this class will have a related twin-function in the relevant
@@ -76,7 +76,7 @@
7676
* The differences between the functions here and the twin functions are documented
7777
* in the docblock of the respective twin-function.
7878
*
79-
* @see \PHP_CodeSniffer\Files\File Source of these utility methods.
79+
* @see \PHP_CodeSniffer\Files\File Original source of these utility methods.
8080
*
8181
* @since 1.0.0
8282
*/
@@ -104,7 +104,8 @@ class BCFile
104104
*
105105
* Note: For ES6 classes in combination with PHPCS 2.x, passing a `T_STRING` token to
106106
* this method will be accepted for JS files.
107-
* Note: support for JS ES6 method syntax has not been back-filled for PHPCS < 3.0.0.
107+
* Note: Support for JS ES6 method syntax has not been back-filled for PHPCS < 3.0.0.
108+
* and sniffing JS files is not officially supported by PHPCSUtils.
108109
*
109110
* @see \PHP_CodeSniffer\Files\File::getDeclarationName() Original source.
110111
* @see \PHPCSUtils\Utils\ObjectDeclarations::getName() PHPCSUtils native improved version.
@@ -232,8 +233,8 @@ public static function getDeclarationName(File $phpcsFile, $stackPtr)
232233
* - PHPCS 3.3.0: The return array now contains a new "type_hint_token" array index.
233234
* - Provides the position in the token stack of the first token in the type declaration.
234235
* - PHPCS 3.3.1: Fixed incompatibility with PHP 7.3.
235-
* - PHPCS 3.5.0: The Exception thrown changed from a `TokenizerException` to
236-
* `\PHP_CodeSniffer\Exceptions\RuntimeException`.
236+
* - PHPCS 3.5.0: The Exception thrown changed from a `\PHP_CodeSniffer\Exceptions\TokenizerException`
237+
* to `\PHP_CodeSniffer\Exceptions\RuntimeException`.
237238
* - PHPCS 3.5.0: Added support for closure USE groups.
238239
* - PHPCS 3.5.0: The return array now contains yet more more information.
239240
* - If a type hint is specified, the position of the last token in the hint will be
@@ -526,8 +527,8 @@ public static function getMethodParameters(File $phpcsFile, $stackPtr)
526527
* - PHPCS 3.4.0: New `has_body` array index.
527528
* - `false` if the method has no body (as with abstract and interface methods)
528529
* or `true` otherwise.
529-
* - PHPCS 3.5.0: The Exception thrown changed from a `TokenizerException` to
530-
* `\PHP_CodeSniffer\Exceptions\RuntimeException`.
530+
* - PHPCS 3.5.0: The Exception thrown changed from a `\PHP_CodeSniffer\Exceptions\TokenizerException`
531+
* to `\PHP_CodeSniffer\Exceptions\RuntimeException`.
531532
* - PHPCS 3.5.3: Added support for PHP 7.4 T_FN arrow functions.
532533
*
533534
* @see \PHP_CodeSniffer\Files\File::getMethodProperties() Original source.
@@ -731,8 +732,8 @@ public static function getMethodProperties(File $phpcsFile, $stackPtr)
731732
* - If the type is nullable, a `nullable_type` array index will also be set to TRUE.
732733
* - If the type contains namespace information, it will be cleaned of whitespace
733734
* and comments in the `type` value.
734-
* - PHPCS 3.5.0: The Exception thrown changed from a `TokenizerException` to
735-
* `\PHP_CodeSniffer\Exceptions\RuntimeException`.
735+
* - PHPCS 3.5.0: The Exception thrown changed from a `\PHP_CodeSniffer\Exceptions\TokenizerException`
736+
* to `\PHP_CodeSniffer\Exceptions\RuntimeException`.
736737
*
737738
* @see \PHP_CodeSniffer\Files\File::getMemberProperties() Original source.
738739
* @see \PHPCSUtils\Utils\Variables::getMemberProperties() PHPCSUtils native improved version.
@@ -899,8 +900,8 @@ public static function getMemberProperties(File $phpcsFile, $stackPtr)
899900
* - Introduced in PHPCS 1.3.0.
900901
* - PHPCS 3.0.0: The Exception thrown changed from a `PHP_CodeSniffer_Exception` to
901902
* `\PHP_CodeSniffer\Exceptions\TokenizerException`.
902-
* - PHPCS 3.5.0: The Exception thrown changed from a `TokenizerException` to
903-
* `\PHP_CodeSniffer\Exceptions\RuntimeException`.
903+
* - PHPCS 3.5.0: The Exception thrown changed from a `\PHP_CodeSniffer\Exceptions\TokenizerException`
904+
* to`\PHP_CodeSniffer\Exceptions\RuntimeException`.
904905
*
905906
* @see \PHP_CodeSniffer\Files\File::getClassProperties() Original source.
906907
* @see \PHPCSUtils\Utils\ObjectDeclarations::getClassProperties() PHPCSUtils native improved version.

PHPCSUtils/BackCompat/BCTokens.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ public static function __callStatic($name, $args)
111111
}
112112

113113
/**
114+
* Tokens that represent assignment operators.
115+
*
114116
* Retrieve the PHPCS assignment tokens array in a cross-version compatible manner.
115117
*
116118
* Changelog for the PHPCS native array:
@@ -146,6 +148,8 @@ public static function assignmentTokens()
146148
}
147149

148150
/**
151+
* Tokens that represent comparison operators.
152+
*
149153
* Retrieve the PHPCS comparison tokens array in a cross-version compatible manner.
150154
*
151155
* Changelog for the PHPCS native array:
@@ -173,6 +177,8 @@ public static function comparisonTokens()
173177
}
174178

175179
/**
180+
* Tokens that represent arithmetic operators.
181+
*
176182
* Retrieve the PHPCS arithmetic tokens array in a cross-version compatible manner.
177183
*
178184
* Changelog for the PHPCS native array:
@@ -193,6 +199,8 @@ public static function arithmeticTokens()
193199
}
194200

195201
/**
202+
* Tokens that perform operations.
203+
*
196204
* Retrieve the PHPCS operator tokens array in a cross-version compatible manner.
197205
*
198206
* Changelog for the PHPCS native array:
@@ -228,6 +236,8 @@ public static function operators()
228236
}
229237

230238
/**
239+
* Token types that open parentheses.
240+
*
231241
* Retrieve the PHPCS parenthesis openers tokens array in a cross-version compatible manner.
232242
*
233243
* Changelog for the PHPCS native array:
@@ -236,9 +246,14 @@ public static function operators()
236246
*
237247
* Note: While `T_LIST` and `T_ANON_CLASS` will be included in the return value for this
238248
* method, the associated parentheses will not have the `'parenthesis_owner'` index set
239-
* until PHPCS 3.5.0.
249+
* until PHPCS 3.5.0. Use the {@see \PHPCSUtils\Utils\Parentheses::getOwner()}
250+
* or {@see \PHPCSUtils\Utils\Parentheses::hasOwner()} methods if you need to check for
251+
* a `T_LIST` or `T_ANON_CLASS` parentheses owner.
240252
*
241253
* @see \PHP_CodeSniffer\Util\Tokens::$parenthesisOpeners Original array.
254+
* @see \PHPCSUtils\Utils\Parentheses Class holding utility methods for
255+
* working with the `'parenthesis_...'`
256+
* index keys in a token array.
242257
*
243258
* @since 1.0.0
244259
*
@@ -254,10 +269,13 @@ public static function parenthesisOpeners()
254269
}
255270

256271
/**
272+
* Tokens that are comments containing PHPCS instructions.
273+
*
257274
* Retrieve the PHPCS comment tokens array in a cross-version compatible manner.
258275
*
259276
* Changelog for the PHPCS native array:
260-
* - Introduced in PHPCS 3.2.3.
277+
* - Introduced in PHPCS 3.2.3. The PHPCS comment tokens, however, were introduced in
278+
* PHPCS 3.2.0.
261279
*
262280
* @see \PHP_CodeSniffer\Util\Tokens::$phpcsCommentTokens Original array.
263281
*
@@ -290,6 +308,8 @@ public static function phpcsCommentTokens()
290308
}
291309

292310
/**
311+
* Tokens that represent text strings.
312+
*
293313
* Retrieve the PHPCS text string tokens array in a cross-version compatible manner.
294314
*
295315
* Changelog for the PHPCS native array:
@@ -311,6 +331,8 @@ public static function textStringTokens()
311331
}
312332

313333
/**
334+
* Tokens that represent the names of called functions.
335+
*
314336
* Retrieve the PHPCS function name tokens array in a cross-version compatible manner.
315337
*
316338
* Changelog for the PHPCS native array:
@@ -333,6 +355,8 @@ public static function functionNameTokens()
333355
}
334356

335357
/**
358+
* Tokens that open class and object scopes.
359+
*
336360
* Retrieve the OO scope tokens array in a cross-version compatible manner.
337361
*
338362
* Changelog for the PHPCS native array:

PHPCSUtils/BackCompat/Helper.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ public static function setConfigData($key, $value, $temp = false, $config = null
9797
/**
9898
* Get the value of a single PHP_CodeSniffer config key.
9999
*
100+
* @see Helper::getCommandLineData() Alternative for the same which is more reliable
101+
* if the `$phpcsFile` object is available.
102+
*
100103
* @since 1.0.0
101104
*
102105
* @param string $key The name of the config value.

0 commit comments

Comments
 (0)