PHP 8.2.31
Preview: NamedArgumentSpacingSniff.php Size: 1.92 KB
/opt/cpanel/ea-wappspector/vendor/slevomat/coding-standard/SlevomatCodingStandard/Sniffs/Functions/NamedArgumentSpacingSniff.php

<?php declare(strict_types = 1);

namespace SlevomatCodingStandard\Sniffs\Functions;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Sniffs\Sniff;
use SlevomatCodingStandard\Helpers\FixerHelper;
use SlevomatCodingStandard\Helpers\TokenHelper;
use function sprintf;
use const T_COLON;
use const T_PARAM_NAME;
use const T_WHITESPACE;

class NamedArgumentSpacingSniff implements Sniff
{

	public const CODE_WHITESPACE_BEFORE_COLON = 'WhitespaceBeforeColon';
	public const CODE_NO_WHITESPACE_AFTER_COLON = 'NoWhitespaceAfterColon';

	/**
	 * @return list<string>
	 */
	public function register(): array
	{
		return [
			T_PARAM_NAME,
		];
	}

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

		/** @var int $colonPointer */
		$colonPointer = TokenHelper::findNext($phpcsFile, T_COLON, $pointer + 1);

		$parameterName = $tokens[$pointer]['content'];

		if ($colonPointer !== $pointer + 1) {
			$fix = $phpcsFile->addFixableError(
				sprintf('There must be no whitespace between named argument "%s" and colon.', $parameterName),
				$colonPointer,
				self::CODE_WHITESPACE_BEFORE_COLON,
			);
			if ($fix) {
				FixerHelper::replace($phpcsFile, $colonPointer - 1, '');
			}
		}

		$whitespacePointer = $colonPointer + 1;

		if (
			$tokens[$whitespacePointer]['code'] === T_WHITESPACE
			&& $tokens[$whitespacePointer]['content'] === ' '
		) {
			return;
		}

		$fix = $phpcsFile->addFixableError(
			sprintf('There must be exactly one space after colon in named argument "%s".', $parameterName),
			$colonPointer,
			self::CODE_NO_WHITESPACE_AFTER_COLON,
		);

		if (!$fix) {
			return;
		}

		if ($tokens[$whitespacePointer]['code'] === T_WHITESPACE) {
			FixerHelper::replace($phpcsFile, $whitespacePointer, ' ');
		} else {
			FixerHelper::add($phpcsFile, $colonPointer, ' ');
		}
	}

}

Directory Contents

Dirs: 0 × Files: 21

Name Size Perms Modified Actions
2.59 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.06 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
755 B 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
925 B lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.58 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.33 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.96 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
1.92 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
4.23 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
7.53 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
5.37 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.72 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.21 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
1.94 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.57 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
3.55 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
3.49 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download
2.13 KB lrw-r--r-- 2025-09-13 08:53:30
Edit Download

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