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

Breadcrumb

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

function DescriptionSniff::process

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

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The current file being processed.:

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

Return value

int

Overrides Sniff::process

File

vendor/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/InfoFiles/DescriptionSniff.php, line 50

Class

DescriptionSniff
Checks if the *.info.yml file contains a description.

Namespace

DrupalPractice\Sniffs\InfoFiles

Code

public function process(File $phpcsFile, $stackPtr) {
    $filename = $phpcsFile->getFilename();
    $fileExtension = strtolower(substr($filename, -9));
    if ($fileExtension !== '.info.yml') {
        return $phpcsFile->numTokens + 1;
    }
    // Exclude config files which might contain the info.yml extension.
    $filenameWithoutExtension = substr($filename, 0, -9);
    if (strpos($filenameWithoutExtension, '.') !== false) {
        return $phpcsFile->numTokens + 1;
    }
    try {
        $info = Yaml::parseFile($phpcsFile->getFilename());
    } catch (ParseException $e) {
        // If the YAML is invalid we ignore this file.
        return $phpcsFile->numTokens + 1;
    }
    // Check if the type key is set, to verify if we're inside a project info.yml file.
    if (isset($info['type']) === false) {
        return $phpcsFile->numTokens + 1;
    }
    if (isset($info['description']) === false) {
        $warning = '"Description" property is missing in the info.yml file';
        $phpcsFile->addWarning($warning, $stackPtr, 'Missing');
    }
    else {
        if ($info['description'] === '') {
            $warning = '"Description" should not be empty';
            $phpcsFile->addWarning($warning, $stackPtr, 'Empty');
        }
    }
    return $phpcsFile->numTokens + 1;
}
RSS feed
Powered by Drupal