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

Breadcrumb

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

function DisallowNewWidgetSniff::process

Processes this test, 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/Objects/DisallowNewWidgetSniff.php, line 42

Class

DisallowNewWidgetSniff

Namespace

PHP_CodeSniffer\Standards\MySource\Sniffs\Objects

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $className = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true);
    if ($tokens[$className]['code'] !== T_STRING) {
        return;
    }
    if (substr(strtolower($tokens[$className]['content']), -10) === 'widgettype') {
        $widgetType = substr($tokens[$className]['content'], 0, -10);
        $error = 'Manual creation of widget objects is banned; use Widget::getWidget(\'%s\'); instead';
        $data = [
            $widgetType,
        ];
        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
    }
}
RSS feed
Powered by Drupal