8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
25 protected $errorMessage =
'Identical operator === is not used for testing the return value of %s function';
111 public function register()
113 return [T_IF, T_ELSEIF];
119 public function process(File $phpcsFile, $stackPtr)
121 $this->tokens = $phpcsFile->getTokens();
122 $this->file = $phpcsFile;
123 $this->leftLimit = $open = $this->tokens[$stackPtr][
'parenthesis_opener'];
124 $this->rightLimit = $close = $this->tokens[$stackPtr][
'parenthesis_closer'];
125 for (
$i = ($open + 1);
$i < $close;
$i++) {
126 if (($this->tokens[
$i][
'code'] === T_STRING && in_array($this->tokens[
$i][
'content'], $this->functions))
129 $foundFunctionName = $this->tokens[
$i][
'content'];
130 $phpcsFile->addError($this->errorMessage,
$i, $this->errorCode, [$foundFunctionName]);
142 protected function findIdentical($leftCurrentPosition, $rightCurrentPosition)
144 $leftBound = $this->file->findPrevious($this->leftRangeTokens, $leftCurrentPosition, $this->leftLimit - 1);
145 $rightBound = $this->file->findNext($this->rightRangeTokens, $rightCurrentPosition, $this->rightLimit + 1);
146 $leftToken = $this->tokens[$leftBound];
147 $rightToken = $this->tokens[$rightBound];
148 if ($leftToken[
'code'] === T_OPEN_PARENTHESIS && $rightToken[
'code'] === T_CLOSE_PARENTHESIS) {
149 return $this->
findIdentical($leftBound - 1, $rightBound + 1);
152 in_array($leftToken[
'code'], $this->identical) || in_array($rightToken[
'code'], $this->identical)
165 $nextOpenParenthesis = $this->file->findNext(T_OPEN_PARENTHESIS, $currentPosition, $this->rightLimit);
166 return $nextOpenParenthesis ? $this->tokens[$nextOpenParenthesis][
'parenthesis_closer'] :
false;
findIdentical($leftCurrentPosition, $rightCurrentPosition)
process(File $phpcsFile, $stackPtr)
findFunctionParenthesisCloser($currentPosition)