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

<?php declare(strict_types = 1);

namespace SlevomatCodingStandard\Sniffs\Classes;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Util\Tokens;
use SlevomatCodingStandard\Helpers\FunctionHelper;
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
use function array_filter;
use function array_keys;
use function array_reduce;
use function array_values;
use function sprintf;

class ClassLengthSniff implements Sniff
{

	public const CODE_CLASS_TOO_LONG = 'ClassTooLong';

	public int $maxLinesLength = 250;

	public bool $includeComments = false;

	public bool $includeWhitespace = false;

	/**
	 * @return array<int, (int|string)>
	 */
	public function register(): array
	{
		return array_values(Tokens::$ooScopeTokens);
	}

	/**
	 * @phpcsSuppress SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingNativeTypeHint
	 * @param int $pointer
	 */
	public function process(File $phpcsFile, $pointer): void
	{
		$this->maxLinesLength = SniffSettingsHelper::normalizeInteger($this->maxLinesLength);
		$flags = array_keys(array_filter([
			FunctionHelper::LINE_INCLUDE_COMMENT => $this->includeComments,
			FunctionHelper::LINE_INCLUDE_WHITESPACE => $this->includeWhitespace,
		]));
		$flags = array_reduce($flags, static fn ($carry, $flag): int => $carry | $flag, 0);

		$length = FunctionHelper::getLineCount($phpcsFile, $pointer, $flags);

		if ($length <= $this->maxLinesLength) {
			return;
		}

		$errorMessage = sprintf('Your class is too long. Currently using %d lines. Can be up to %d lines.', $length, $this->maxLinesLength);

		$phpcsFile->addError($errorMessage, $pointer, self::CODE_CLASS_TOO_LONG);
	}

}

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).