Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. GenderNeutralCommentSniff.php

class GenderNeutralCommentSniff

Parses and verifies that comments use gender neutral language.

@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer

Hierarchy

  • class \Drupal\Sniffs\Commenting\GenderNeutralCommentSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of GenderNeutralCommentSniff

File

vendor/drupal/coder/coder_sniffer/Drupal/Sniffs/Commenting/GenderNeutralCommentSniff.php, line 22

Namespace

Drupal\Sniffs\Commenting
View source
class GenderNeutralCommentSniff implements Sniff {
    
    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register() {
        return [
            T_COMMENT,
            T_DOC_COMMENT_STRING,
        ];
    }
    
    //end register()
    
    /**
     * Processes this test, when one of its tokens is encountered.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
     * @param int                         $stackPtr  The position of the current token
     *                                               in the stack passed in $tokens.
     *
     * @return void
     */
    public function process(File $phpcsFile, $stackPtr) {
        $tokens = $phpcsFile->getTokens();
        if ((bool) preg_match('/(^|\\W)(he|her|hers|him|his|she)($|\\W)/i', $tokens[$stackPtr]['content']) === true) {
            $phpcsFile->addError('Unnecessarily gendered language in a comment', $stackPtr, 'GenderNeutral');
        }
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
GenderNeutralCommentSniff::process public function Processes this test, when one of its tokens is encountered. Overrides Sniff::process
GenderNeutralCommentSniff::register public function Returns an array of tokens this test wants to listen for. Overrides Sniff::register
RSS feed
Powered by Drupal