RequiredSniff.php in Coder 8.3
File
coder_sniffer/Drupal/Sniffs/InfoFiles/RequiredSniff.php
View source
<?php
namespace Drupal\Sniffs\InfoFiles;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
class RequiredSniff implements Sniff {
public function register() {
return [
T_INLINE_HTML,
];
}
public function process(File $phpcsFile, $stackPtr) {
$fileExtension = strtolower(substr($phpcsFile
->getFilename(), -4));
if ($fileExtension !== 'info') {
return $phpcsFile->numTokens + 1;
}
$contents = file_get_contents($phpcsFile
->getFilename());
$info = ClassFilesSniff::drupalParseInfoFormat($contents);
if (isset($info['name']) === false) {
$error = '"name" property is missing in the info file';
$phpcsFile
->addError($error, $stackPtr, 'Name');
}
if (isset($info['description']) === false) {
$error = '"description" property is missing in the info file';
$phpcsFile
->addError($error, $stackPtr, 'Description');
}
if (isset($info['core']) === false) {
$error = '"core" property is missing in the info file';
$phpcsFile
->addError($error, $stackPtr, 'Core');
}
else {
if ($info['core'] === '7.x' && isset($info['php']) === true && $info['php'] <= '5.2') {
$error = 'Drupal 7 core already requires PHP 5.2';
$ptr = ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile);
$phpcsFile
->addError($error, $ptr, 'D7PHPVersion');
}
}
return $phpcsFile->numTokens + 1;
}
}
Classes
Name |
Description |
RequiredSniff |
"name", "description" and "core are required fields in Drupal info files. Also
checks the "php" minimum requirement for Drupal 7. |