function RequireNullSafeObjectOperatorSniff::process
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *
Parameters
int $identicalPointer:
Overrides Sniff::process
File
-
vendor/
slevomat/ coding-standard/ SlevomatCodingStandard/ Sniffs/ ControlStructures/ RequireNullSafeObjectOperatorSniff.php, line 62
Class
Namespace
SlevomatCodingStandard\Sniffs\ControlStructuresCode
public function process(File $phpcsFile, $identicalPointer) : int {
$this->enable = SniffSettingsHelper::isEnabledByPhpVersion($this->enable, 80000);
if (!$this->enable) {
return $identicalPointer + 1;
}
$tokens = $phpcsFile->getTokens();
[
$pointerBeforeIdentical,
$pointerAfterIdentical,
] = $this->getIdenticalData($phpcsFile, $identicalPointer);
if ($tokens[$pointerBeforeIdentical]['code'] !== T_NULL && $tokens[$pointerAfterIdentical]['code'] !== T_NULL) {
return $identicalPointer + 1;
}
[
$identificatorStartPointer,
$identificatorEndPointer,
$conditionStartPointer,
] = $this->getConditionData($phpcsFile, $pointerBeforeIdentical, $pointerAfterIdentical);
if ($identificatorStartPointer === null || $identificatorEndPointer === null) {
return $identicalPointer + 1;
}
$isYoda = $tokens[$pointerBeforeIdentical]['code'] === T_NULL;
$identificator = IdentificatorHelper::getContent($phpcsFile, $identificatorStartPointer, $identificatorEndPointer);
$pointerAfterCondition = TokenHelper::findNextEffective($phpcsFile, ($isYoda ? $identificatorEndPointer : $pointerAfterIdentical) + 1);
$allowedBooleanCondition = $tokens[$identicalPointer]['code'] === T_IS_NOT_IDENTICAL ? T_BOOLEAN_AND : T_BOOLEAN_OR;
if ($tokens[$pointerAfterCondition]['code'] === $allowedBooleanCondition) {
return $this->checkNextCondition($phpcsFile, $identicalPointer, $conditionStartPointer, $identificator, $pointerAfterCondition);
}
if ($tokens[$pointerAfterCondition]['code'] === T_INLINE_THEN) {
$this->checkTernaryOperator($phpcsFile, $identicalPointer, $conditionStartPointer, $identificator, $pointerAfterCondition);
return $pointerAfterCondition + 1;
}
return $identicalPointer + 1;
}