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

Breadcrumb

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

function UselessParenthesesSniff::checkParenthesesAroundString

1 call to UselessParenthesesSniff::checkParenthesesAroundString()
UselessParenthesesSniff::process in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/PHP/UselessParenthesesSniff.php
* @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint *

File

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

Class

UselessParenthesesSniff

Namespace

SlevomatCodingStandard\Sniffs\PHP

Code

private function checkParenthesesAroundString(File $phpcsFile, int $parenthesisOpenerPointer) : void {
    $tokens = $phpcsFile->getTokens();
    
    /** @var int $stringPointer */
    $stringPointer = TokenHelper::findNextEffective($phpcsFile, $parenthesisOpenerPointer + 1);
    if ($tokens[$stringPointer]['code'] !== T_CONSTANT_ENCAPSED_STRING) {
        return;
    }
    $pointerAfterString = TokenHelper::findNextEffective($phpcsFile, $stringPointer + 1);
    if ($pointerAfterString !== $tokens[$parenthesisOpenerPointer]['parenthesis_closer']) {
        return;
    }
    $fix = $phpcsFile->addFixableError('Useless parentheses.', $parenthesisOpenerPointer, self::CODE_USELESS_PARENTHESES);
    if (!$fix) {
        return;
    }
    $phpcsFile->fixer
        ->beginChangeset();
    FixerHelper::removeBetweenIncluding($phpcsFile, $parenthesisOpenerPointer, $stringPointer - 1);
    FixerHelper::removeBetweenIncluding($phpcsFile, $stringPointer + 1, $tokens[$parenthesisOpenerPointer]['parenthesis_closer']);
    $phpcsFile->fixer
        ->endChangeset();
}

API Navigation

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