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

Breadcrumb

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

function UselessParenthesesSniff::process

* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

Parameters

int $parenthesisOpenerPointer:

Overrides Sniff::process

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php, line 117

Class

UselessParenthesesSniff

Namespace

SlevomatCodingStandard\Sniffs\PHP

Code

public function process(File $phpcsFile, $parenthesisOpenerPointer) : void {
    $tokens = $phpcsFile->getTokens();
    if (array_key_exists('parenthesis_owner', $tokens[$parenthesisOpenerPointer])) {
        return;
    }
    if (!array_key_exists('parenthesis_closer', $tokens[$parenthesisOpenerPointer])) {
        return;
    }
    
    /** @var int $pointerBeforeParenthesisOpener */
    $pointerBeforeParenthesisOpener = TokenHelper::findPreviousEffective($phpcsFile, $parenthesisOpenerPointer - 1);
    if (in_array($tokens[$pointerBeforeParenthesisOpener]['code'], array_merge(TokenHelper::getNameTokenCodes(), [
        T_VARIABLE,
        T_ISSET,
        T_UNSET,
        T_EMPTY,
        T_CLOSURE,
        T_FN,
        T_USE,
        T_ANON_CLASS,
        T_NEW,
        T_SELF,
        T_STATIC,
        T_PARENT,
        T_EXIT,
        T_CLOSE_PARENTHESIS,
        T_EVAL,
        T_LIST,
        T_INCLUDE,
        T_INCLUDE_ONCE,
        T_REQUIRE,
        T_REQUIRE_ONCE,
        T_INT_CAST,
        T_DOUBLE_CAST,
        T_STRING_CAST,
        T_ARRAY_CAST,
        T_OBJECT_CAST,
        T_BOOL_CAST,
        T_UNSET_CAST,
        T_MATCH,
    ]), true)) {
        return;
    }
    
    /** @var int $pointerAfterParenthesisOpener */
    $pointerAfterParenthesisOpener = TokenHelper::findNextEffective($phpcsFile, $parenthesisOpenerPointer + 1);
    if (in_array($tokens[$pointerAfterParenthesisOpener]['code'], [
        T_NEW,
        T_CLONE,
        T_YIELD,
        T_YIELD_FROM,
        T_REQUIRE,
        T_REQUIRE_ONCE,
        T_INCLUDE,
        T_INCLUDE_ONCE,
        T_ARRAY_CAST,
    ], true)) {
        return;
    }
    if (TokenHelper::findNext($phpcsFile, T_EQUAL, $parenthesisOpenerPointer + 1, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']) !== null) {
        return;
    }
    $pointerAfterParenthesisCloser = TokenHelper::findNextEffective($phpcsFile, $tokens[$parenthesisOpenerPointer]['parenthesis_closer'] + 1);
    if ($pointerAfterParenthesisCloser !== null && $tokens[$pointerAfterParenthesisCloser]['code'] === T_OPEN_PARENTHESIS) {
        return;
    }
    if (IdentificatorHelper::findStartPointer($phpcsFile, $pointerBeforeParenthesisOpener) !== null) {
        return;
    }
    $this->checkParenthesesAroundConditionInTernaryOperator($phpcsFile, $parenthesisOpenerPointer);
    $this->checkParenthesesAroundCaseInSwitch($phpcsFile, $parenthesisOpenerPointer);
    $this->checkParenthesesAroundVariableOrFunctionCall($phpcsFile, $parenthesisOpenerPointer);
    $this->checkParenthesesAroundString($phpcsFile, $parenthesisOpenerPointer);
    $this->checkParenthesesAroundOperators($phpcsFile, $parenthesisOpenerPointer);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal