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

Breadcrumb

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

class SuppressHelper

@internal

Hierarchy

  • class \SlevomatCodingStandard\Helpers\SuppressHelper

Expanded class hierarchy of SuppressHelper

7 files declare their use of SuppressHelper
DisallowMixedTypeHintSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/DisallowMixedTypeHintSniff.php
NullableTypeForNullDefaultValueSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/NullableTypeForNullDefaultValueSniff.php
ParameterTypeHintSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/ParameterTypeHintSniff.php
PropertyTypeHintSniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/TypeHints/PropertyTypeHintSniff.php
ReferenceThrowableOnlySniff.php in vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Exceptions/ReferenceThrowableOnlySniff.php

... See full list

File

vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SuppressHelper.php, line 19

Namespace

SlevomatCodingStandard\Helpers
View source
class SuppressHelper {
    public const ANNOTATION = '@phpcsSuppress';
    public static function isSniffSuppressed(File $phpcsFile, int $pointer, string $suppressName) : bool {
        
        /** @var list<Annotation<GenericTagValueNode>> $annotations */
        $annotations = AnnotationHelper::getAnnotations($phpcsFile, $pointer, self::ANNOTATION);
        return array_reduce($annotations, static function (bool $carry, Annotation $annotation) use ($suppressName) : bool {
            $annotationSuppressName = explode(' ', $annotation->getValue()->value)[0];
            if ($suppressName === $annotationSuppressName || strpos($suppressName, sprintf('%s.', $annotationSuppressName)) === 0) {
                $carry = true;
            }
            return $carry;
        }, false);
    }
    public static function removeSuppressAnnotation(File $phpcsFile, int $pointer, string $suppressName) : void {
        $suppressAnnotation = null;
        
        /** @var Annotation<GenericTagValueNode> $annotation */
        foreach (AnnotationHelper::getAnnotations($phpcsFile, $pointer, self::ANNOTATION) as $annotation) {
            if ($annotation->getValue()->value === $suppressName) {
                $suppressAnnotation = $annotation;
                break;
            }
        }
        assert($suppressAnnotation !== null);
        $tokens = $phpcsFile->getTokens();
        
        /** @var int $pointerBefore */
        $pointerBefore = TokenHelper::findPrevious($phpcsFile, [
            T_DOC_COMMENT_OPEN_TAG,
            T_DOC_COMMENT_STAR,
        ], $suppressAnnotation->getStartPointer() - 1);
        $changeStart = $tokens[$pointerBefore]['code'] === T_DOC_COMMENT_STAR ? $pointerBefore : $suppressAnnotation->getStartPointer();
        
        /** @var int $changeEnd */
        $changeEnd = TokenHelper::findNext($phpcsFile, [
            T_DOC_COMMENT_CLOSE_TAG,
            T_DOC_COMMENT_STAR,
        ], $suppressAnnotation->getEndPointer() + 1) - 1;
        $phpcsFile->fixer
            ->beginChangeset();
        FixerHelper::removeBetweenIncluding($phpcsFile, $changeStart, $changeEnd);
        $phpcsFile->fixer
            ->endChangeset();
    }

}

Members

Title Sort descending Modifiers Object type Summary
SuppressHelper::ANNOTATION public constant
SuppressHelper::isSniffSuppressed public static function
SuppressHelper::removeSuppressAnnotation public static function

API Navigation

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