coder-8.x-3.x-dev/coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php

coder_sniffer/DrupalPractice/Sniffs/Commenting/AuthorTagSniff.php
<?php
/**
 * \DrupalPractice\Sniffs\Commenting\AuthorTagSniff.
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @link     http://pear.php.net/package/PHP_CodeSniffer
 */

namespace DrupalPractice\Sniffs\Commenting;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;

/**
 * Checks the usage of @author tags.
 *
 * @category PHP
 * @package  PHP_CodeSniffer
 * @link     http://pear.php.net/package/PHP_CodeSniffer
 */
class AuthorTagSniff implements Sniff
{


    /**
     * Returns an array of tokens this test wants to listen for.
     *
     * @return array<int|string>
     */
    public function register()
    {
        return [T_DOC_COMMENT_TAG];
    }


    /**
     * 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();

        $content = $tokens[$stackPtr]['content'];
        if ($content === '@author' || $content === '@author:') {
            $warning = '@author tags are not usually used in Drupal, because over time multiple contributors will touch the code anyway';
            $phpcsFile->addWarning($warning, $stackPtr, 'AuthorFound');
        }
    }
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc