class StrictSchemaDisabledSniff
Checks that $strictConfigSchema is not set to FALSE in test classes.
@category PHP @package PHP_CodeSniffer @link http://pear.php.net/package/PHP_CodeSniffer
Hierarchy
- class \PHP_CodeSniffer\Sniffs\AbstractScopeSniff implements \PHP_CodeSniffer\Sniffs\Sniff
- class \PHP_CodeSniffer\Sniffs\AbstractVariableSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff
- class \DrupalPractice\Sniffs\Objects\StrictSchemaDisabledSniff extends \PHP_CodeSniffer\Sniffs\AbstractVariableSniff
- class \PHP_CodeSniffer\Sniffs\AbstractVariableSniff extends \PHP_CodeSniffer\Sniffs\AbstractScopeSniff
Expanded class hierarchy of StrictSchemaDisabledSniff
File
-
vendor/
drupal/ coder/ coder_sniffer/ DrupalPractice/ Sniffs/ Objects/ StrictSchemaDisabledSniff.php, line 22
Namespace
DrupalPractice\Sniffs\ObjectsView source
class StrictSchemaDisabledSniff extends AbstractVariableSniff {
/**
* The name of the variable in the test base class to disable config schema checking.
*/
const STRICT_CONFIG_SCHEMA_NAME = '$strictConfigSchema';
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
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
}
//end processMemberVar()
/**
* Determine if this class is a test class.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return bool
* Returns TRUE if the current class is a test class.
*/
protected function isTestClass(File $phpcsFile, $stackPtr) {
// Only applies to test classes, which have Test in the name.
$tokens = $phpcsFile->getTokens();
$classPtr = key($tokens[$stackPtr]['conditions']);
$name = $phpcsFile->findNext([
T_STRING,
], $classPtr);
return strpos($tokens[$name]['content'], 'Test') !== false;
}
//end isTestClass()
/**
* Called to process normal member vars.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the token was found.
*
* @return void|int Optionally returns a stack pointer. The sniff will not be
* called again on the current file until the returned stack
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
* the rest of the file.
*/
protected function processVariable(File $phpcsFile, $stackPtr) {
}
//end processVariable()
/**
* Called to process variables found in double quoted strings or heredocs.
*
* Note that there may be more than one variable in the string, which will
* result only in one call for the string or one call per line for heredocs.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where this
* token was found.
* @param int $stackPtr The position where the double quoted
* string was found.
*
* @return void|int Optionally returns a stack pointer. The sniff will not be
* called again on the current file until the returned stack
* pointer is reached. Return ($phpcsFile->numTokens + 1) to skip
* the rest of the file.
*/
protected function processVariableInString(File $phpcsFile, $stackPtr) {
}
//end processVariableInString()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
AbstractScopeSniff::$listenOutside | private | property | True if this test should fire on tokens outside of the scope. | |
AbstractScopeSniff::$scopeTokens | private | property | The type of scope opener tokens that this test wishes to listen to. | |
AbstractScopeSniff::$tokens | private | property | The token types that this test wishes to listen to within the scope. | |
AbstractScopeSniff::process | final public | function | Processes the tokens that this test is listening for. | Overrides Sniff::process |
AbstractScopeSniff::register | final public | function | The method that is called to register the tokens this test wishes to listen to. |
Overrides Sniff::register |
AbstractVariableSniff::$phpReservedVars | protected | property | List of PHP Reserved variables. | |
AbstractVariableSniff::processTokenOutsideScope | final protected | function | Processes the token outside the scope in the file. | Overrides AbstractScopeSniff::processTokenOutsideScope |
AbstractVariableSniff::processTokenWithinScope | final protected | function | Processes the token in the specified PHP_CodeSniffer\Files\File. | Overrides AbstractScopeSniff::processTokenWithinScope |
AbstractVariableSniff::__construct | public | function | Constructs an AbstractVariableTest. | Overrides AbstractScopeSniff::__construct |
StrictSchemaDisabledSniff::isTestClass | protected | function | Determine if this class is a test class. | |
StrictSchemaDisabledSniff::processMemberVar | public | function | Processes this test, when one of its tokens is encountered. | Overrides AbstractVariableSniff::processMemberVar |
StrictSchemaDisabledSniff::processVariable | protected | function | Called to process normal member vars. | Overrides AbstractVariableSniff::processVariable |
StrictSchemaDisabledSniff::processVariableInString | protected | function | Called to process variables found in double quoted strings or heredocs. | Overrides AbstractVariableSniff::processVariableInString |
StrictSchemaDisabledSniff::STRICT_CONFIG_SCHEMA_NAME | constant | The name of the variable in the test base class to disable config schema checking. |