Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RequireNullSafeObjectOperatorSniff.php

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

RequireNullSafeObjectOperatorSniff

Namespace

SlevomatCodingStandard\Sniffs\ControlStructures

Code

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;
}
RSS feed
Powered by Drupal