AutoAddedKeysSniff.php in Coder 8.3.x
File
coder_sniffer/Drupal/Sniffs/InfoFiles/AutoAddedKeysSniff.php
View source
<?php
namespace Drupal\Sniffs\InfoFiles;
use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
class AutoAddedKeysSniff implements Sniff {
public function register() {
return [
T_INLINE_HTML,
];
}
public function process(File $phpcsFile, $stackPtr) {
if (preg_match('/\\.info$/', $phpcsFile
->getFilename()) === 1) {
$contents = file_get_contents($phpcsFile
->getFilename());
$info = ClassFilesSniff::drupalParseInfoFormat($contents);
}
else {
if (preg_match('/\\.info\\.yml$/', $phpcsFile
->getFilename()) === 1) {
$contents = file_get_contents($phpcsFile
->getFilename());
try {
$info = \Symfony\Component\Yaml\Yaml::parse($contents);
} catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
return $phpcsFile->numTokens + 1;
}
}
else {
return $phpcsFile->numTokens + 1;
}
}
if (isset($info['project']) === true) {
$warning = 'Remove "project" from the info file, it will be added by drupal.org packaging automatically';
$phpcsFile
->addWarning($warning, $stackPtr, 'Project');
}
if (isset($info['datestamp']) === true) {
$warning = 'Remove "datestamp" from the info file, it will be added by drupal.org packaging automatically';
$phpcsFile
->addWarning($warning, $stackPtr, 'Timestamp');
}
if (isset($info['version']) === true && strpos($phpcsFile
->getFilename(), '/core/') === false) {
$warning = 'Remove "version" from the info file, it will be added by drupal.org packaging automatically';
$phpcsFile
->addWarning($warning, $stackPtr, 'Version');
}
return $phpcsFile->numTokens + 1;
}
}
Classes
Name |
Description |
AutoAddedKeysSniff |
"version", "project" and "timestamp" are added automatically by drupal.org
packaging scripts. |