function CognitiveSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $stackPtr:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ Complexity/ CognitiveSniff.php, line 140
Class
- CognitiveSniff
- Cognitive Complexity
Namespace
SlevomatCodingStandard\Sniffs\ComplexityCode
public function process(File $phpcsFile, $stackPtr) : void {
$this->phpcsFile = $phpcsFile;
if ($phpcsFile->getCondition($stackPtr, T_FUNCTION) !== false) {
return;
}
if ($this->maxComplexity !== null) {
// maxComplexity is deprecated... if set use it
$this->warningThreshold = $this->maxComplexity + 1;
$this->errorThreshold = $this->maxComplexity + 1;
}
$cognitiveComplexity = $this->computeForFunctionFromTokensAndPosition($stackPtr);
if ($cognitiveComplexity < $this->warningThreshold) {
return;
}
$name = $phpcsFile->getDeclarationName($stackPtr);
$errorParameters = [
'Cognitive complexity for "%s" is %d but has to be less than or equal to %d.',
$stackPtr,
self::CODE_COMPLEXITY,
[
$name,
$cognitiveComplexity,
$this->warningThreshold - 1,
],
];
$cognitiveComplexity >= $this->errorThreshold ? $phpcsFile->addError(...$errorParameters) : $phpcsFile->addWarning(...$errorParameters);
}