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

Breadcrumb

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

function IncludeOwnSystemSniff::process

Processes this sniff, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

int $stackPtr The position of the current token in: the stack passed in $tokens.

Return value

void

Overrides Sniff::process

File

vendor/squizlabs/php_codesniffer/src/Standards/MySource/Sniffs/Channels/IncludeOwnSystemSniff.php, line 42

Class

IncludeOwnSystemSniff

Namespace

PHP_CodeSniffer\Standards\MySource\Sniffs\Channels

Code

public function process(File $phpcsFile, $stackPtr) {
    $fileName = $phpcsFile->getFilename();
    $matches = [];
    if (preg_match('|/systems/(.*)/([^/]+)?actions.inc$|i', $fileName, $matches) === 0) {
        // Not an actions file.
        return;
    }
    $ownClass = $matches[2];
    $tokens = $phpcsFile->getTokens();
    $typeName = $phpcsFile->findNext(T_CONSTANT_ENCAPSED_STRING, $stackPtr + 2, null, false, true);
    $typeName = trim($tokens[$typeName]['content'], " '");
    switch (strtolower($tokens[$stackPtr + 1]['content'])) {
        case 'includesystem':
            $included = strtolower($typeName);
            break;
        case 'includeasset':
            $included = strtolower($typeName) . 'assettype';
            break;
        case 'includewidget':
            $included = strtolower($typeName) . 'widgettype';
            break;
        default:
            return;
    }
    if ($included === strtolower($ownClass)) {
        $error = "You do not need to include \"%s\" from within the system's own actions file";
        $data = [
            $ownClass,
        ];
        $phpcsFile->addError($error, $stackPtr, 'NotRequired', $data);
    }
}
RSS feed
Powered by Drupal