public function RoutingAccessSniff::process in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php \DrupalPractice\Sniffs\Yaml\RoutingAccessSniff::process()
- 8.3.x coder_sniffer/DrupalPractice/Sniffs/Yaml/RoutingAccessSniff.php \DrupalPractice\Sniffs\Yaml\RoutingAccessSniff::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
File
- coder_sniffer/
DrupalPractice/ Sniffs/ Yaml/ RoutingAccessSniff.php, line 50
Class
- RoutingAccessSniff
- Checks that there are no undocumented open access callbacks in *.routing.yml files.
Namespace
DrupalPractice\Sniffs\YamlCode
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile
->getTokens();
$fileExtension = strtolower(substr($phpcsFile
->getFilename(), -12));
if ($fileExtension !== '.routing.yml') {
return $phpcsFile->numTokens + 1;
}
if (preg_match('/^[\\s]+_access: \'TRUE\'/', $tokens[$stackPtr]['content']) === 1 && isset($tokens[$stackPtr - 1]) === true && preg_match('/^[\\s]*#/', $tokens[$stackPtr - 1]['content']) === 0) {
$warning = 'Open page callback found, please add a comment before the line why there is no access restriction';
$phpcsFile
->addWarning($warning, $stackPtr, 'OpenCallback');
}
if (preg_match('/^[\\s]+_permission: \'access administration pages\'/', $tokens[$stackPtr]['content']) === 1) {
$warning = 'The administration page callback should probably use "administer site configuration" - which implies the user can change something - rather than "access administration pages" which is about viewing but not changing configurations.';
$phpcsFile
->addWarning($warning, $stackPtr, 'PermissionFound');
}
}