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

Breadcrumb

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

function StrictSchemaDisabledSniff::processMemberVar

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 AbstractVariableSniff::processMemberVar

File

vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Objects/StrictSchemaDisabledSniff.php, line 40

Class

StrictSchemaDisabledSniff
Checks that $strictConfigSchema is not set to FALSE in test classes.

Namespace

DrupalPractice\Sniffs\Objects

Code

public function processMemberVar(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    if ($tokens[$stackPtr]['content'] === static::STRICT_CONFIG_SCHEMA_NAME && $this->isTestClass($phpcsFile, $stackPtr) === true) {
        $find = [
            T_FALSE,
            T_TRUE,
            T_NULL,
            T_SEMICOLON,
        ];
        $next = $phpcsFile->findNext($find, $stackPtr + 1);
        // If this variable is being set, the only allowed value is TRUE.
        // Otherwise if FALSE or NULL, schema checking is disabled.
        if ($tokens[$next]['code'] !== T_TRUE) {
            $error = 'Do not disable strict config schema checking in tests. Instead ensure your module properly declares its schema for configurations.';
            $data = [
                $tokens[$stackPtr]['content'],
            ];
            $phpcsFile->addError($error, $stackPtr, 'StrictConfigSchema', $data);
        }
    }
    
    //end if
}
RSS feed
Powered by Drupal