Mercurial > hg > cmmr2012-drupal-site
comparison vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php @ 5:12f9dff5fda9 tip
Update to Drupal core 8.7.1
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 15:34:47 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:a9cd425dd02b | 5:12f9dff5fda9 |
---|---|
1 <?php | |
2 /** | |
3 * Parses and verifies comment language. | |
4 * | |
5 * @category PHP | |
6 * @package PHP_CodeSniffer | |
7 * @link http://pear.php.net/package/PHP_CodeSniffer | |
8 */ | |
9 | |
10 namespace Drupal\Sniffs\Commenting; | |
11 | |
12 use PHP_CodeSniffer\Files\File; | |
13 use PHP_CodeSniffer\Sniffs\Sniff; | |
14 | |
15 /** | |
16 * Parses and verifies that comments use gender neutral language. | |
17 * | |
18 * @category PHP | |
19 * @package PHP_CodeSniffer | |
20 * @link http://pear.php.net/package/PHP_CodeSniffer | |
21 */ | |
22 class GenderNeutralCommentSniff implements Sniff | |
23 { | |
24 | |
25 | |
26 /** | |
27 * Returns an array of tokens this test wants to listen for. | |
28 * | |
29 * @return array | |
30 */ | |
31 public function register() | |
32 { | |
33 return array( | |
34 T_COMMENT, | |
35 T_DOC_COMMENT_STRING, | |
36 ); | |
37 | |
38 }//end register() | |
39 | |
40 | |
41 /** | |
42 * Processes this test, when one of its tokens is encountered. | |
43 * | |
44 * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned. | |
45 * @param int $stackPtr The position of the current token | |
46 * in the stack passed in $tokens. | |
47 * | |
48 * @return void | |
49 */ | |
50 public function process(File $phpcsFile, $stackPtr) | |
51 { | |
52 $tokens = $phpcsFile->getTokens(); | |
53 if ((bool) preg_match('/(^|\W)(he|her|hers|him|his|she)($|\W)/i', $tokens[$stackPtr]['content']) === true) { | |
54 $phpcsFile->addError('Unnecessarily gendered language in a comment', $stackPtr, 'GenderNeutral'); | |
55 } | |
56 | |
57 }//end process() | |
58 | |
59 | |
60 }//end class |