PHP 8.2.31
Preview: SuppressHelper.php Size: 2.27 KB
/opt/cpanel/ea-wappspector/vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/SuppressHelper.php

<?php declare(strict_types = 1);

namespace SlevomatCodingStandard\Helpers;

use PHP_CodeSniffer\Files\File;
use PHPStan\PhpDocParser\Ast\PhpDoc\GenericTagValueNode;
use function array_reduce;
use function assert;
use function explode;
use function sprintf;
use function strpos;
use const T_DOC_COMMENT_CLOSE_TAG;
use const T_DOC_COMMENT_OPEN_TAG;
use const T_DOC_COMMENT_STAR;

/**
 * @internal
 */
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();
	}

}

Directory Contents

Dirs: 0 × Files: 41

Name Size Perms Modified Actions
1.11 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
8.67 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
10.15 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
6.25 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.60 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.14 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.00 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.18 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.03 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
430 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.52 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
10.20 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.03 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
7.12 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
502 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.97 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
16.55 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
7.34 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.84 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.80 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
893 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.27 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.56 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
6.39 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.32 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
15.13 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.48 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.20 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.01 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
485 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.27 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
4.97 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
12.87 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
774 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
740 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
966 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
10.67 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.53 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
7.82 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.03 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
9.28 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).