PHP 8.2.31
Preview: PropertySpacingSniff.php Size: 2.61 KB
/opt/cpanel/ea-wappspector/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Classes/PropertySpacingSniff.php

<?php declare(strict_types = 1);

namespace SlevomatCodingStandard\Sniffs\Classes;

use PHP_CodeSniffer\Files\File;
use SlevomatCodingStandard\Helpers\PropertyHelper;
use SlevomatCodingStandard\Helpers\TokenHelper;
use function in_array;
use function sprintf;
use const T_AS;
use const T_CLASS;
use const T_CONST;
use const T_FUNCTION;
use const T_VARIABLE;

class PropertySpacingSniff extends AbstractPropertyConstantAndEnumCaseSpacing
{

	public const CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_PROPERTY = 'IncorrectCountOfBlankLinesAfterProperty';

	/**
	 * @return array<int, (int|string)>
	 */
	public function register(): array
	{
		return TokenHelper::PROPERTY_MODIFIERS_TOKEN_CODES;
	}

	/**
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
	 * @param int $pointer
	 */
	public function process(File $phpcsFile, $pointer): int
	{
		$tokens = $phpcsFile->getTokens();

		$asPointer = TokenHelper::findPreviousEffective($phpcsFile, $pointer - 1);
		if ($tokens[$asPointer]['code'] === T_AS) {
			return $pointer;
		}

		$nextPointer = TokenHelper::findNextEffective($phpcsFile, $pointer + 1);
		if (in_array($tokens[$nextPointer]['code'], TokenHelper::PROPERTY_MODIFIERS_TOKEN_CODES, true)) {
			// We don't want to report the same property multiple times
			return $nextPointer;
		}

		// Ignore other class members with same mofidiers
		$propertyPointer = TokenHelper::findNext($phpcsFile, [T_VARIABLE, T_FUNCTION, T_CONST, T_CLASS], $pointer + 1);
		if (
			$propertyPointer === null
			|| $tokens[$propertyPointer]['code'] !== T_VARIABLE
			|| !PropertyHelper::isProperty($phpcsFile, $propertyPointer)
		) {
			return $propertyPointer ?? $pointer;
		}

		return parent::process($phpcsFile, $propertyPointer);
	}

	protected function isNextMemberValid(File $phpcsFile, int $pointer): bool
	{
		$nextPointer = TokenHelper::findNext($phpcsFile, [T_FUNCTION, T_VARIABLE], $pointer + 1);

		return $nextPointer !== null && $phpcsFile->getTokens()[$nextPointer]['code'] === T_VARIABLE;
	}

	protected function addError(File $phpcsFile, int $pointer, int $minExpectedLines, int $maxExpectedLines, int $found): bool
	{
		if ($minExpectedLines === $maxExpectedLines) {
			$errorMessage = $minExpectedLines === 1
				? 'Expected 1 blank line after property, found %3$d.'
				: 'Expected %2$d blank lines after property, found %3$d.';
		} else {
			$errorMessage = 'Expected %1$d to %2$d blank lines after property, found %3$d.';
		}
		$error = sprintf($errorMessage, $minExpectedLines, $maxExpectedLines, $found);

		return $phpcsFile->addFixableError($error, $pointer, self::CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_PROPERTY);
	}

}

Directory Contents

Dirs: 0 × Files: 36

Name Size Perms Modified Actions
1.78 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.64 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.37 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.46 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.62 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
8.68 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
27.29 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.32 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.73 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.79 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.85 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
4.63 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.19 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.12 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.60 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.28 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.22 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
460 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
4.88 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.37 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
12.84 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.61 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.50 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
11.76 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.39 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.20 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.43 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.81 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.27 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.29 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.63 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.13 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.65 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
9.52 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
306 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.76 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download

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