diff --git a/PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php b/PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php index 90585ae..c51ba59 100644 --- a/PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php +++ b/PSR2R/Sniffs/Commenting/DocBlockNoEmptySniff.php @@ -42,7 +42,7 @@ public function process(File $phpcsFile, $stackPtr) { * * @return void */ - protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex) { + protected function assertNonEmptyDocBlock(File $phpcsFile, int $stackPtr, int $endIndex): void { $nextIndex = $phpcsFile->findNext([T_WHITESPACE, T_DOC_COMMENT_WHITESPACE, T_DOC_COMMENT_STAR], $stackPtr + 1, $endIndex - 1, true); if ($nextIndex) { return; @@ -63,7 +63,7 @@ protected function assertNonEmptyDocBlock(File $phpcsFile, $stackPtr, $endIndex) * * @return void */ - protected function assertNoEmptyTag(File $phpcsFile, $stackPtr, $endIndex) { + protected function assertNoEmptyTag(File $phpcsFile, int $stackPtr, int $endIndex): void { $tokens = $phpcsFile->getTokens(); $index = $stackPtr; diff --git a/PSR2R/Sniffs/Commenting/DocBlockParamSniff.php b/PSR2R/Sniffs/Commenting/DocBlockParamSniff.php index ce37e62..c94be51 100644 --- a/PSR2R/Sniffs/Commenting/DocBlockParamSniff.php +++ b/PSR2R/Sniffs/Commenting/DocBlockParamSniff.php @@ -134,7 +134,7 @@ public function process(File $phpCsFile, $stackPointer): void { * * @return array */ - private function getMethodSignature(File $phpCsFile, $stackPtr) { + private function getMethodSignature(File $phpCsFile, int $stackPtr): array { $tokens = $phpCsFile->getTokens(); $startIndex = $phpCsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1); diff --git a/PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php b/PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php index 94ab074..16d8ee3 100644 --- a/PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php +++ b/PSR2R/Sniffs/Commenting/DocBlockReturnSelfSniff.php @@ -115,7 +115,7 @@ protected function isNonChainable(array $tokens, int $stackPointer): bool { * * @return void */ - protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) { + protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void { $result = []; foreach ($parts as $key => $part) { if ($part !== 'self') { diff --git a/PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php b/PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php index 6ee3139..19dd435 100644 --- a/PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php +++ b/PSR2R/Sniffs/Commenting/DocBlockShortTypeSniff.php @@ -82,7 +82,7 @@ public function process(File $phpCsFile, $stackPointer): void { * * @return void */ - protected function fixParts(File $phpCsFile, $classNameIndex, array $parts, $appendix) { + protected function fixParts(File $phpCsFile, int $classNameIndex, array $parts, string $appendix): void { $mapping = [ 'boolean' => 'bool', 'integer' => 'int', diff --git a/PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php b/PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php index eb2f876..436e674 100644 --- a/PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php +++ b/PSR2R/Sniffs/Commenting/DocBlockTagTypesSniff.php @@ -16,7 +16,7 @@ class DocBlockTagTypesSniff extends AbstractSniff { /** * @var array */ - protected static $whitelistedTags = [ + protected static array $whitelistedTags = [ '@api', '@author', '@copyright', @@ -92,7 +92,7 @@ class DocBlockTagTypesSniff extends AbstractSniff { /** * @var array */ - protected static $blacklistedTags = [ + protected static array $blacklistedTags = [ '@package', '@subpackage', '@global', @@ -105,7 +105,7 @@ class DocBlockTagTypesSniff extends AbstractSniff { /** * @var array */ - protected static $mapping = [ + protected static array $mapping = [ '@type' => '@var', '@overwrite' => '@override', '@inheritdoc' => '@inheritDoc', @@ -121,7 +121,7 @@ class DocBlockTagTypesSniff extends AbstractSniff { * * @var string */ - public $whitelist = ''; + public string $whitelist = ''; /** * @inheritDoc @@ -196,7 +196,7 @@ public function process(File $phpcsFile, $stackPtr) { /** * @return void */ - protected function prepareWhitelist() { + protected function prepareWhitelist(): void { if (!empty($this->whitelist)) { $whitelist = explode(',', $this->whitelist); foreach ($whitelist as $tag) { diff --git a/PSR2R/Sniffs/Commenting/DocCommentSniff.php b/PSR2R/Sniffs/Commenting/DocCommentSniff.php index de4d82e..a9e653a 100644 --- a/PSR2R/Sniffs/Commenting/DocCommentSniff.php +++ b/PSR2R/Sniffs/Commenting/DocCommentSniff.php @@ -30,7 +30,7 @@ class DocCommentSniff extends AbstractSniff { * * @var array */ - public $supportedTokenizers = [ + public array $supportedTokenizers = [ 'PHP', 'JS', ]; diff --git a/PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php b/PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php index 2466fcc..4e401bf 100644 --- a/PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php +++ b/PSR2R/Sniffs/ControlStructures/ConditionalExpressionOrderSniff.php @@ -105,11 +105,11 @@ public function process(File $phpCsFile, $stackPointer): void { /** * @param \PHP_CodeSniffer\Files\File $phpCsFile * @param int $index - * @param int $limit + * @param int|null $limit * * @return int|null */ - protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) { + protected function detectRightEnd(File $phpCsFile, int $index, ?int $limit = 0): ?int { $tokens = $phpCsFile->getTokens(); $rightEndIndex = $index; @@ -163,12 +163,12 @@ protected function detectRightEnd(File $phpCsFile, $index, $limit = 0) { * @return void */ protected function applyFix(File $phpCsFile, - $index, - $leftIndexStart, - $leftIndexEnd, - $rightIndexStart, - $rightIndexEnd, - ) { + int $index, + int $leftIndexStart, + int $leftIndexEnd, + int $rightIndexStart, + int $rightIndexEnd, + ): void { $tokens = $phpCsFile->getTokens(); $token = $tokens[$index]; @@ -200,7 +200,7 @@ protected function applyFix(File $phpCsFile, * * @return string */ - protected function getComparisonValue(array $token) { + protected function getComparisonValue(array $token): string { $comparisonIndexValue = $token['content']; $operatorsToMap = [T_GREATER_THAN, T_LESS_THAN, T_IS_GREATER_OR_EQUAL, T_IS_SMALLER_OR_EQUAL]; if (in_array($token['code'], $operatorsToMap, true)) { diff --git a/PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php b/PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php index af5093a..bdde3be 100644 --- a/PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php +++ b/PSR2R/Sniffs/ControlStructures/ControlStructureSpacingSniff.php @@ -32,9 +32,8 @@ class ControlStructureSpacingSniff implements Sniff { /** * How many spaces should follow the opening bracket. * - * @var int */ - public $requiredSpacesAfterOpen = 0; + public int $requiredSpacesAfterOpen = 0; /** * @inheritDoc @@ -57,9 +56,8 @@ public function register(): array { /** * How many spaces should precede the closing bracket. * - * @var int */ - public $requiredSpacesBeforeClose = 0; + public int $requiredSpacesBeforeClose = 0; /** * @inheritDoc diff --git a/PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php b/PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php index df4e83d..8b37b3f 100644 --- a/PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php +++ b/PSR2R/Sniffs/ControlStructures/NoInlineAssignmentSniff.php @@ -36,10 +36,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkMethodCalls(File $phpcsFile, $stackPtr) { + protected function checkMethodCalls(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $openingBraceIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1, $stackPtr + 4); @@ -63,10 +63,10 @@ protected function checkMethodCalls(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkConditions($phpcsFile, $stackPtr) { + protected function checkConditions(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $openingBraceIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); @@ -99,7 +99,7 @@ protected function checkConditions($phpcsFile, $stackPtr) { * * @return bool */ - protected function isFixableInlineAssignment(File $phpcsFile, $startIndex, $endIndex, &$indexEqualSign) { + protected function isFixableInlineAssignment(File $phpcsFile, int $startIndex, int $endIndex, int &$indexEqualSign): bool { $tokens = $phpcsFile->getTokens(); $hasInlineAssignment = false; diff --git a/PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php b/PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php index 433fe7d..e2464fe 100644 --- a/PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php +++ b/PSR2R/Sniffs/ControlStructures/TernarySpacingSniff.php @@ -34,10 +34,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function assertSpaceBefore(File $phpcsFile, $stackPtr) { + protected function assertSpaceBefore(File $phpcsFile, int $stackPtr): void { $previous = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); if ($stackPtr - $previous > 1) { $this->assertSingleSpaceBeforeIfNotMultiline($phpcsFile, $stackPtr, $previous); @@ -58,10 +58,10 @@ protected function assertSpaceBefore(File $phpcsFile, $stackPtr) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr * @param int $previous -* + * * @return void */ - protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stackPtr, $previous) { + protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, int $stackPtr, int $previous): void { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['line'] !== $tokens[$previous]['line']) { @@ -81,10 +81,10 @@ protected function assertSingleSpaceBeforeIfNotMultiline(File $phpcsFile, $stack /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $thenIndex -* + * * @return void */ - protected function checkAfter(File $phpcsFile, $thenIndex) { + protected function checkAfter(File $phpcsFile, int $thenIndex): void { $elseIndex = $phpcsFile->findNext(T_INLINE_ELSE, $thenIndex + 1); if (!$elseIndex) { return; @@ -106,10 +106,10 @@ protected function checkAfter(File $phpcsFile, $thenIndex) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $thenIndex * @param int $elseIndex -* + * * @return void */ - protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex) { + protected function assertNoSpaceBetween(File $phpcsFile, int $thenIndex, int $elseIndex): void { if ($elseIndex - $thenIndex === 1) { return; } @@ -128,10 +128,10 @@ protected function assertNoSpaceBetween(File $phpcsFile, $thenIndex, $elseIndex) /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function assertSpaceAfter(File $phpcsFile, $stackPtr) { + protected function assertSpaceAfter(File $phpcsFile, int $stackPtr): void { $nextIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); if ($nextIndex - $stackPtr > 1) { $this->assertSingleSpaceAfterIfNotMultiline($phpcsFile, $stackPtr, $nextIndex); @@ -152,10 +152,10 @@ protected function assertSpaceAfter(File $phpcsFile, $stackPtr) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr * @param int $next -* + * * @return void */ - protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, $stackPtr, $next) { + protected function assertSingleSpaceAfterIfNotMultiline(File $phpcsFile, int $stackPtr, int $next): void { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['line'] !== $tokens[$next]['line']) { diff --git a/PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php b/PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php index e954e47..35f7602 100644 --- a/PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php +++ b/PSR2R/Sniffs/ControlStructures/UnneededElseSniff.php @@ -132,10 +132,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return bool */ - protected function isNotLastCondition(File $phpcsFile, $stackPtr) { + protected function isNotLastCondition(File $phpcsFile, int $stackPtr): bool { $tokens = $phpcsFile->getTokens(); // Abort if not known @@ -160,7 +160,7 @@ protected function isNotLastCondition(File $phpcsFile, $stackPtr) { * * @return void */ - protected function fixElseIfToIf(File $phpcsFile, $stackPtr) { + protected function fixElseIfToIf(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $phpcsFile->fixer->beginChangeset(); diff --git a/PSR2R/Sniffs/Methods/MethodDeclarationSniff.php b/PSR2R/Sniffs/Methods/MethodDeclarationSniff.php index d80f6e1..b937878 100644 --- a/PSR2R/Sniffs/Methods/MethodDeclarationSniff.php +++ b/PSR2R/Sniffs/Methods/MethodDeclarationSniff.php @@ -36,18 +36,15 @@ public function __construct() { } /** - * @param \PHP_CodeSniffer\Files\File $phpcsFile - * @param int $stackPtr -* - * @return void + * @inheritDoc */ - protected function processTokenOutsideScope(File $phpcsFile, $stackPtr) { + protected function processTokenOutsideScope(File $phpcsFile, $stackPtr): void { // Nothing to do here. } /** * @inheritDoc -* + * * @throws \PHP_CodeSniffer\Exceptions\RuntimeException */ protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope) { diff --git a/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php b/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php index 7467a9a..bc2a37d 100644 --- a/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php +++ b/PSR2R/Sniffs/Namespaces/NoInlineFullyQualifiedClassNameSniff.php @@ -18,34 +18,34 @@ class NoInlineFullyQualifiedClassNameSniff extends AbstractSniff { use NamespaceTrait; /** - * @var array + * @var array|null */ - protected $existingStatements; + protected ?array $existingStatements = null; /** * @var array */ - protected $newStatements = []; + protected array $newStatements = []; /** * @var array */ - protected $allStatements; + protected array $allStatements; /** * @var array */ - protected $useStatements; + protected array $useStatements; /** * @var int Last token we will process */ - protected $sentinelPtr; + protected int $sentinelPtr; /** - * @var \PHP_CodeSniffer\Files\File + * @var \PHP_CodeSniffer\Files\File|null */ - protected $sentinelFile; + protected ?\PHP_CodeSniffer\Files\File $sentinelFile = null; /** * @inheritDoc @@ -56,7 +56,7 @@ public function register(): array { /** * @inheritDoc -* + * * @throws \RuntimeException */ public function process(File $phpcsFile, $stackPtr) { @@ -92,7 +92,7 @@ public function process(File $phpcsFile, $stackPtr) { * * @return void */ - protected function loadStatements(File $phpcsFile) { + protected function loadStatements(File $phpcsFile): void { if ($this->existingStatements !== null) { return; } @@ -105,10 +105,10 @@ protected function loadStatements(File $phpcsFile) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile -* + * * @return array */ - protected function getUseStatements(File $phpcsFile) { + protected function getUseStatements(File $phpcsFile): array { $tokens = $phpcsFile->getTokens(); $statements = []; @@ -177,16 +177,16 @@ protected function getUseStatements(File $phpcsFile) { * * @return bool */ - protected function isMultipleUseStatement($statementContent) { + protected function isMultipleUseStatement(string $statementContent): bool { return strpos($statementContent, ',') !== false; } /** * @param \PHP_CodeSniffer\Files\File $phpcsFile -* + * * @return void */ - protected function findSentinel(File $phpcsFile) { + protected function findSentinel(File $phpcsFile): void { if ($this->sentinelFile !== $phpcsFile) { $tokens = $phpcsFile->getTokens(); $last = count($tokens) - 1; @@ -201,12 +201,12 @@ protected function findSentinel(File $phpcsFile) { * * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForClass(File $phpcsFile, $stackPtr) { + protected function checkUseForClass(File $phpcsFile, int $stackPtr): void { $nextIndex = $phpcsFile->findNext(T_EXTENDS, $stackPtr + 1); if ($nextIndex) { $this->checkUseForExtends($phpcsFile, $nextIndex); @@ -221,12 +221,12 @@ protected function checkUseForClass(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $nextIndex -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForExtends(File $phpcsFile, $nextIndex) { + protected function checkUseForExtends(File $phpcsFile, int $nextIndex): void { $endIndex = $phpcsFile->findNext([T_IMPLEMENTS, T_CURLY_OPEN, T_OPEN_CURLY_BRACKET], $nextIndex + 1); $startIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $nextIndex + 1, null, true); @@ -271,10 +271,10 @@ protected function checkUseForExtends(File $phpcsFile, $nextIndex) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $startIndex * @param int $endIndex -* + * * @return array */ - protected function extractUseStatements(File $phpcsFile, $startIndex, $endIndex) { + protected function extractUseStatements(File $phpcsFile, int $startIndex, int $endIndex): array { $tokens = $phpcsFile->getTokens(); $result = []; @@ -313,10 +313,10 @@ protected function extractUseStatements(File $phpcsFile, $startIndex, $endIndex) * @param array $tokens * @param int $start * @param int $end -* + * * @return string */ - protected function extractUseStatementsAsString(array $tokens, $start, $end) { + protected function extractUseStatementsAsString(array $tokens, int $start, int $end): string { $string = ''; for ($i = $start; $i <= $end; ++$i) { $string .= $tokens[$i]['content']; @@ -329,10 +329,10 @@ protected function extractUseStatementsAsString(array $tokens, $start, $end) { /** * @param string $useStatement -* + * * @return string */ - protected function extractClassNameFromUseStatementAsString($useStatement) { + protected function extractClassNameFromUseStatementAsString(string $useStatement): string { $lastSeparator = strrpos($useStatement, '\\'); if ($lastSeparator === false) { return $useStatement; @@ -346,10 +346,10 @@ protected function extractClassNameFromUseStatementAsString($useStatement) { * @param string $fullName * * @throws \RuntimeException -* + * * @return array */ - protected function addUseStatement($shortName, $fullName) { + protected function addUseStatement(string $shortName, string $fullName): array { foreach ($this->allStatements as $useStatement) { if ($useStatement['fullName'] === $fullName) { return $useStatement; @@ -380,7 +380,7 @@ protected function addUseStatement($shortName, $fullName) { * * @return string|null */ - protected function generateUniqueAlias($shortName, $fullName) { + protected function generateUniqueAlias(string $shortName, string $fullName): ?string { $alias = $shortName; $count = 0; $pieces = explode('\\', $fullName); @@ -414,22 +414,22 @@ protected function generateUniqueAlias($shortName, $fullName) { /** * @param array $useStatement -* + * * @return void */ - protected function insertUseStatement(array $useStatement) { + protected function insertUseStatement(array $useStatement): void { $this->useStatements[] = $useStatement; } /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $nextIndex -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForImplements(File $phpcsFile, $nextIndex) { + protected function checkUseForImplements(File $phpcsFile, int $nextIndex): void { $endIndex = $phpcsFile->findNext([T_OPEN_CURLY_BRACKET], $nextIndex + 1); $startIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $nextIndex + 1, null, true); @@ -470,12 +470,12 @@ protected function checkUseForImplements(File $phpcsFile, $nextIndex) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForNew(File $phpcsFile, $stackPtr) { + protected function checkUseForNew(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $nextIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); @@ -538,12 +538,12 @@ protected function checkUseForNew(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForStatic(File $phpcsFile, $stackPtr) { + protected function checkUseForStatic(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $prevIndex = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true); @@ -605,7 +605,7 @@ protected function checkUseForStatic(File $phpcsFile, $stackPtr) { * * @return void */ - protected function checkUseForInstanceOf(File $phpcsFile, $stackPtr) { + protected function checkUseForInstanceOf(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $classNameIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); @@ -670,7 +670,7 @@ protected function checkUseForInstanceOf(File $phpcsFile, $stackPtr) { * * @return void */ - public function checkUseForCatchOrCallable(File $phpcsFile, $stackPtr) { + public function checkUseForCatchOrCallable(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $openParenthesisIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1); @@ -740,7 +740,7 @@ public function checkUseForCatchOrCallable(File $phpcsFile, $stackPtr) { * * @return void */ - protected function checkUseForReturnTypeHint(File $phpcsFile, $stackPtr) { + protected function checkUseForReturnTypeHint(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $openParenthesisIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1); @@ -814,12 +814,12 @@ protected function checkUseForReturnTypeHint(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @throws \RuntimeException -* + * * @return void */ - protected function checkUseForSignature(File $phpcsFile, $stackPtr) { + protected function checkUseForSignature(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $openParenthesisIndex = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr + 1); @@ -888,10 +888,10 @@ protected function checkUseForSignature(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function insertUseWhenSentinel(File $phpcsFile, $stackPtr) { + protected function insertUseWhenSentinel(File $phpcsFile, int $stackPtr): void { if (($stackPtr === $this->sentinelPtr) && count($this->useStatements)) { $existingStatements = $this->existingStatements; $haveExistingStatements = $existingStatements; @@ -925,7 +925,7 @@ protected function insertUseWhenSentinel(File $phpcsFile, $stackPtr) { * * @return string */ - protected function generateUseStatement(array $useStatement) { + protected function generateUseStatement(array $useStatement): string { $alias = ''; if (!empty($useStatement['alias'])) { $alias = ' as ' . $useStatement['alias']; @@ -939,7 +939,7 @@ protected function generateUseStatement(array $useStatement) { * * @return bool */ - protected function isBlacklistedFile(File $phpcsFile) { + protected function isBlacklistedFile(File $phpcsFile): bool { $file = $phpcsFile->getFilename(); return strpos($file, DIRECTORY_SEPARATOR . 'Fixtures' . DIRECTORY_SEPARATOR) !== false; diff --git a/PSR2R/Sniffs/PHP/ListCommaSniff.php b/PSR2R/Sniffs/PHP/ListCommaSniff.php index 190877b..5126903 100644 --- a/PSR2R/Sniffs/PHP/ListCommaSniff.php +++ b/PSR2R/Sniffs/PHP/ListCommaSniff.php @@ -53,10 +53,10 @@ public function process(File $phpcsFile, $stackPtr) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $startIndex * @param int $endIndex -* + * * @return void */ - protected function clearRange(File $phpcsFile, $startIndex, $endIndex) { + protected function clearRange(File $phpcsFile, int $startIndex, int $endIndex): void { for ($i = $startIndex; $i <= $endIndex; $i++) { $phpcsFile->fixer->replaceToken($i, ''); } diff --git a/PSR2R/Sniffs/WhiteSpace/ArraySpacingSniff.php b/PSR2R/Sniffs/WhiteSpace/ArraySpacingSniff.php index abc690f..5c95f0b 100644 --- a/PSR2R/Sniffs/WhiteSpace/ArraySpacingSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/ArraySpacingSniff.php @@ -35,10 +35,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkBeginning(File $phpcsFile, $stackPtr) { + protected function checkBeginning(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $nextIndex = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true); @@ -58,10 +58,10 @@ protected function checkBeginning(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkEnding(File $phpcsFile, $stackPtr) { + protected function checkEnding(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $previousIndex = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); diff --git a/PSR2R/Sniffs/WhiteSpace/DocBlockAlignmentSniff.php b/PSR2R/Sniffs/WhiteSpace/DocBlockAlignmentSniff.php index e306b76..8929810 100644 --- a/PSR2R/Sniffs/WhiteSpace/DocBlockAlignmentSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/DocBlockAlignmentSniff.php @@ -150,10 +150,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index -* + * * @return int|null */ - protected function findFirstNonWhitespaceInLine(File $phpcsFile, $index) { + protected function findFirstNonWhitespaceInLine(File $phpcsFile, int $index): ?int { $tokens = $phpcsFile->getTokens(); $firstIndex = $index; diff --git a/PSR2R/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php b/PSR2R/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php index a0eb870..7b638ec 100644 --- a/PSR2R/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/EmptyEnclosingLineSniff.php @@ -52,10 +52,10 @@ public function process(File $phpcsFile, $stackPtr) { * @param int $curlyBraceStartIndex * @param int $curlyBraceEndIndex * @param int $lastContentIndex -* + * * @return void */ - protected function checkEnd(File $phpcsFile, $stackPtr, $curlyBraceStartIndex, $curlyBraceEndIndex, $lastContentIndex) { + protected function checkEnd(File $phpcsFile, int $stackPtr, int $curlyBraceStartIndex, int $curlyBraceEndIndex, int $lastContentIndex): void { $tokens = $phpcsFile->getTokens(); if ($lastContentIndex === $curlyBraceStartIndex) { @@ -103,10 +103,10 @@ protected function checkEnd(File $phpcsFile, $stackPtr, $curlyBraceStartIndex, $ * @param int $curlyBraceStartIndex * @param int $curlyBraceEndIndex * @param int $lastContentIndex -* + * * @return void */ - public function checkBeginning(File $phpcsFile, $stackPtr, $curlyBraceStartIndex, $curlyBraceEndIndex, $lastContentIndex) { + public function checkBeginning(File $phpcsFile, int $stackPtr, int $curlyBraceStartIndex, int $curlyBraceEndIndex, int $lastContentIndex): void { $tokens = $phpcsFile->getTokens(); if ($lastContentIndex === $curlyBraceStartIndex) { diff --git a/PSR2R/Sniffs/WhiteSpace/EmptyLinesSniff.php b/PSR2R/Sniffs/WhiteSpace/EmptyLinesSniff.php index c790eb7..6223924 100644 --- a/PSR2R/Sniffs/WhiteSpace/EmptyLinesSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/EmptyLinesSniff.php @@ -13,7 +13,7 @@ class EmptyLinesSniff extends AbstractSniff { /** * @var array */ - public $supportedTokenizers = [ + public array $supportedTokenizers = [ 'PHP', 'JS', 'CSS', @@ -39,7 +39,7 @@ public function process(File $phpcsFile, $stackPtr) { * * @return void */ - protected function assertMaximumOneEmptyLineBetweenContent(File $phpcsFile, $stackPtr) { + protected function assertMaximumOneEmptyLineBetweenContent(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); if ($tokens[$stackPtr]['content'] === $phpcsFile->eolChar && isset($tokens[($stackPtr + 1)]) diff --git a/PSR2R/Sniffs/WhiteSpace/MethodSpacingSniff.php b/PSR2R/Sniffs/WhiteSpace/MethodSpacingSniff.php index 71b1b65..1b16384 100644 --- a/PSR2R/Sniffs/WhiteSpace/MethodSpacingSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/MethodSpacingSniff.php @@ -85,7 +85,7 @@ public function process(File $phpcsFile, $stackPtr) { * * @return void */ - protected function assertNoAdditionalNewlinesForEmptyBody(File $phpcsFile, $from, $to) { + protected function assertNoAdditionalNewlinesForEmptyBody(File $phpcsFile, int $from, int $to): void { $tokens = $phpcsFile->getTokens(); $startLine = $tokens[$from]['line']; diff --git a/PSR2R/Sniffs/WhiteSpace/TabAndSpaceSniff.php b/PSR2R/Sniffs/WhiteSpace/TabAndSpaceSniff.php index d637e1f..5f632eb 100644 --- a/PSR2R/Sniffs/WhiteSpace/TabAndSpaceSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/TabAndSpaceSniff.php @@ -29,7 +29,7 @@ class TabAndSpaceSniff implements Sniff { * * @var array */ - public $supportedTokenizers = [ + public array $supportedTokenizers = [ 'PHP', 'JS', 'CSS', diff --git a/PSR2R/Sniffs/WhiteSpace/TabIndentSniff.php b/PSR2R/Sniffs/WhiteSpace/TabIndentSniff.php index 2b81c1f..7db38e3 100644 --- a/PSR2R/Sniffs/WhiteSpace/TabIndentSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/TabIndentSniff.php @@ -18,7 +18,7 @@ class TabIndentSniff implements Sniff { * * @var array */ - public $supportedTokenizers = [ + public array $supportedTokenizers = [ 'PHP', 'JS', 'CSS', @@ -71,7 +71,7 @@ public function process(File $phpcsFile, $stackPtr) { * * @return void */ - protected function fixTab(File $phpcsFile, $stackPtr, $tokens) { + protected function fixTab(File $phpcsFile, int $stackPtr, array $tokens): void { $content = $tokens[$stackPtr]['orig_content'] ?? $tokens[$stackPtr]['content']; $tabs = 0; while (strpos($content, ' ') === 0) { @@ -95,7 +95,7 @@ protected function fixTab(File $phpcsFile, $stackPtr, $tokens) { * * @return void */ - protected function fixSpace(File $phpcsFile, $stackPtr, $tokens) { + protected function fixSpace(File $phpcsFile, int $stackPtr, array $tokens): void { $content = $tokens[$stackPtr]['content']; $newContent = str_replace("\t", ' ', $content); diff --git a/PSR2R/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php b/PSR2R/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php index a6e22ee..5e9dc15 100644 --- a/PSR2R/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php +++ b/PSR2R/Sniffs/WhiteSpace/UnaryOperatorSpacingSniff.php @@ -92,10 +92,10 @@ public function process(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkBefore(File $phpcsFile, $stackPtr) { + protected function checkBefore(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $prevIndex = $phpcsFile->findPrevious(T_WHITESPACE, $stackPtr - 1, null, true); @@ -118,10 +118,10 @@ protected function checkBefore(File $phpcsFile, $stackPtr) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $stackPtr -* + * * @return void */ - protected function checkAfter(File $phpcsFile, $stackPtr) { + protected function checkAfter(File $phpcsFile, int $stackPtr): void { $tokens = $phpcsFile->getTokens(); $nextIndex = $phpcsFile->findNext(T_WHITESPACE, $stackPtr + 1, null, true); diff --git a/PSR2R/Tools/AbstractSniff.php b/PSR2R/Tools/AbstractSniff.php index 1f8eb2f..133834b 100644 --- a/PSR2R/Tools/AbstractSniff.php +++ b/PSR2R/Tools/AbstractSniff.php @@ -10,17 +10,17 @@ abstract class AbstractSniff implements Sniff { /** * @var array These markers must remain as inline comments */ - protected static $phpStormMarkers = ['@noinspection']; + protected static array $phpStormMarkers = ['@noinspection']; /** * Checks if the given token is of this token code/type. * * @param array|string|int $search * @param array $token -* + * * @return bool */ - protected function isGivenKind($search, array $token) { + protected function isGivenKind(array|string|int $search, array $token): bool { $search = (array)$search; if (in_array($token['code'], $search, true)) { return true; @@ -40,10 +40,10 @@ protected function isGivenKind($search, array $token) { * @param int $start * @param int $end * @param bool $skipNested -* + * * @return bool */ - protected function contains(File $phpcsFile, $search, $start, $end, $skipNested = true) { + protected function contains(File $phpcsFile, array|string|int $search, int $start, int $end, bool $skipNested = true): bool { $tokens = $phpcsFile->getTokens(); for ($i = $start; $i <= $end; $i++) { @@ -77,10 +77,10 @@ protected function contains(File $phpcsFile, $search, $start, $end, $skipNested * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $openingBraceIndex * @param int $closingBraceIndex -* + * * @return bool */ - protected function needsBrackets(File $phpcsFile, $openingBraceIndex, $closingBraceIndex) { + protected function needsBrackets(File $phpcsFile, int $openingBraceIndex, int $closingBraceIndex): bool { $tokens = $phpcsFile->getTokens(); $whitelistedCodes = [ @@ -147,10 +147,10 @@ protected function findRelatedDocBlock(File $phpCsFile, int $stackPointer): ?int * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index * @param int $count -* + * * @return void */ - protected function outdent(File $phpcsFile, $index, $count = 1) { + protected function outdent(File $phpcsFile, int $index, int $count = 1): void { $tokens = $phpcsFile->getTokens(); $char = $this->getIndentationCharacter($tokens[$index]['content'], true); @@ -165,10 +165,10 @@ protected function outdent(File $phpcsFile, $index, $count = 1) { * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index * @param int $count -* + * * @return void */ - protected function indent(File $phpcsFile, $index, $count = 1) { + protected function indent(File $phpcsFile, int $index, int $count = 1): void { $tokens = $phpcsFile->getTokens(); $char = $this->getIndentationCharacter($tokens[$index]['content'], true); @@ -180,10 +180,10 @@ protected function indent(File $phpcsFile, $index, $count = 1) { * @param string $search * @param string $replace * @param string $subject -* + * * @return string */ - protected function strReplaceOnce($search, $replace, $subject) { + protected function strReplaceOnce(string $search, string $replace, string $subject): string { $pos = strpos($subject, $search); if ($pos === false) { return $subject; @@ -197,10 +197,10 @@ protected function strReplaceOnce($search, $replace, $subject) { * * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index -* + * * @return int */ - protected function getIndentationLevel(File $phpcsFile, $index) { + protected function getIndentationLevel(File $phpcsFile, int $index): int { $tokens = $phpcsFile->getTokens(); $whitespace = $this->getIndentationWhitespace($phpcsFile, $index); @@ -218,10 +218,10 @@ protected function getIndentationLevel(File $phpcsFile, $index) { /** * @param string $content * @param bool $correctLength -* + * * @return string */ - protected function getIndentationCharacter($content, $correctLength = false) { + protected function getIndentationCharacter(string $content, bool $correctLength = false): string { if (strpos($content, "\n")) { $parts = explode("\n", $content); array_shift($parts); @@ -246,10 +246,10 @@ protected function getIndentationCharacter($content, $correctLength = false) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index -* + * * @return string */ - protected function getIndentationWhitespace(File $phpcsFile, $index) { + protected function getIndentationWhitespace(File $phpcsFile, int $index): string { $tokens = $phpcsFile->getTokens(); $firstIndex = $this->getFirstTokenOfLine($tokens, $index); @@ -264,10 +264,10 @@ protected function getIndentationWhitespace(File $phpcsFile, $index) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile * @param int $index -* + * * @return int */ - protected function getIndentationColumn(File $phpcsFile, $index) { + protected function getIndentationColumn(File $phpcsFile, int $index): int { $tokens = $phpcsFile->getTokens(); $firstIndex = $this->getFirstTokenOfLine($tokens, $index); @@ -283,10 +283,10 @@ protected function getIndentationColumn(File $phpcsFile, $index) { /** * @param array $tokens * @param int $index -* + * * @return int */ - protected function getFirstTokenOfLine(array $tokens, $index) { + protected function getFirstTokenOfLine(array $tokens, int $index): int { $line = $tokens[$index]['line']; $currentIndex = $index; @@ -299,19 +299,19 @@ protected function getFirstTokenOfLine(array $tokens, $index) { /** * @param \PHP_CodeSniffer\Files\File $phpCsFile -* + * * @return bool */ - protected function hasNamespace(File $phpCsFile) { + protected function hasNamespace(File $phpCsFile): bool { return $this->findNamespaceIndex($phpCsFile) !== null; } /** * @param \PHP_CodeSniffer\Files\File $phpCsFile -* + * * @return int|null */ - protected function findNamespaceIndex(File $phpCsFile) { + protected function findNamespaceIndex(File $phpCsFile): ?int { $namespacePosition = $phpCsFile->findNext(T_NAMESPACE, 0); if (!$namespacePosition) { return null; @@ -322,10 +322,10 @@ protected function findNamespaceIndex(File $phpCsFile) { /** * @param \PHP_CodeSniffer\Files\File $phpcsFile -* + * * @return array */ - protected function getNamespaceInfo(File $phpcsFile) { + protected function getNamespaceInfo(File $phpcsFile): array { $startIndex = $this->findNamespaceIndex($phpcsFile); $endIndex = 0; @@ -352,7 +352,7 @@ protected function getNamespaceInfo(File $phpcsFile) { * * @return string */ - protected function getNamespaceAsString(File $phpCsFile, $startIndex, $endIndex) { + protected function getNamespaceAsString(File $phpCsFile, int $startIndex, int $endIndex): string { $tokens = $phpCsFile->getTokens(); $namespace = ''; @@ -366,10 +366,10 @@ protected function getNamespaceAsString(File $phpCsFile, $startIndex, $endIndex) /** * @param \PHP_CodeSniffer\Files\File $phpCsFile * @param int $stackPtr -* + * * @return bool */ - protected function isPhpStormMarker(File $phpCsFile, $stackPtr) { + protected function isPhpStormMarker(File $phpCsFile, int $stackPtr): bool { $tokens = $phpCsFile->getTokens(); $line = $tokens[$stackPtr]['line']; if ($tokens[$stackPtr]['type'] !== 'T_DOC_COMMENT_OPEN_TAG') { diff --git a/PSR2R/Tools/SniffsAndTests.php b/PSR2R/Tools/SniffsAndTests.php index b48a3d7..7c71423 100644 --- a/PSR2R/Tools/SniffsAndTests.php +++ b/PSR2R/Tools/SniffsAndTests.php @@ -17,7 +17,7 @@ class SniffsAndTests { /** * @var array */ - protected static $orgs = [ + protected static array $orgs = [ 'PSR2R', ]; diff --git a/PSR2R/Tools/Tokenizer.php b/PSR2R/Tools/Tokenizer.php index f391597..8e362d2 100644 --- a/PSR2R/Tools/Tokenizer.php +++ b/PSR2R/Tools/Tokenizer.php @@ -24,24 +24,24 @@ class Tokenizer { /** * @var string */ - protected $root; + protected string $root; /** * @var string */ - protected $path; + protected string $path; /** * @var bool */ - protected $verbose; + protected bool $verbose; /** * @param array $argv -* + * * @throws \Exception */ - public function __construct($argv) { + public function __construct(array $argv) { $file = !empty($argv[1]) ? $argv[1] : null; if (!$file || !file_exists($file)) { throw new Exception('Please provide a valid file.'); @@ -56,7 +56,7 @@ public function __construct($argv) { /** * @return void */ - public function tokenize() { + public function tokenize(): void { $res = []; $tokens = $this->_getTokens($this->path); @@ -79,10 +79,10 @@ public function tokenize() { /** * @param string $path Path -* + * * @return array Tokens */ - protected function _getTokens($path) { + protected function _getTokens(string $path): array { $phpcs = new Runner(); define('PHP_CODESNIFFER_CBF', false); @@ -105,10 +105,10 @@ protected function _getTokens($path) { /** * @param int $row Current row * @param array $tokens Tokens array -* + * * @return array */ - protected function _tokenize($row, $tokens) { + protected function _tokenize(int $row, array $tokens): array { $pieces = []; foreach ($tokens as $key => $token) { if ($token['line'] > $row) { diff --git a/composer.json b/composer.json index 5595603..041906a 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ ], "require": { "php": ">=8.1", - "php-collective/code-sniffer": "^0.1.0", + "php-collective/code-sniffer": "dev-next", "slevomat/coding-standard": "^8.3.0", "squizlabs/php_codesniffer": "^3.7.0" }, diff --git a/phpcs.xml b/phpcs.xml index e9de998..007c9c6 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -10,6 +10,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + ,*.inc,*.fixed