Skip to content

Commit

Permalink
SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing: Fixed fals…
Browse files Browse the repository at this point in the history
…e positive when parameter has attribute but no type hint
  • Loading branch information
kukulich committed Dec 14, 2022
1 parent 326d195 commit c51edb8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use SlevomatCodingStandard\Helpers\TypeHintHelper;
use function array_keys;
use function sprintf;
use const T_ATTRIBUTE_END;
use const T_BITWISE_AND;
use const T_COMMA;
use const T_ELLIPSIS;
Expand Down Expand Up @@ -63,7 +64,14 @@ public function process(File $phpcsFile, $functionPointer): void
$parameterEndPointer = $parametersEndPointer;
}

$typeHintEndPointer = TokenHelper::findPrevious($phpcsFile, $typeHintTokenCodes, $parameterPointer - 1, $parameterStartPointer);
$attributeCloserPointer = TokenHelper::findPrevious($phpcsFile, T_ATTRIBUTE_END, $parameterPointer - 1, $parameterStartPointer);

$typeHintEndPointer = TokenHelper::findPrevious(
$phpcsFile,
$typeHintTokenCodes,
$parameterPointer - 1,
$attributeCloserPointer ?? $parameterStartPointer
);
if ($typeHintEndPointer === null) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php // lint >= 8.0
<?php // lint >= 8.1

$a = function (?bool $a, ?string &$b, ?int ...$c)
{
Expand All @@ -8,7 +8,9 @@
function b(
?bool $a,
array $b,
$c
#[SomeAttribute]
$c,
$d
) {

}
Expand Down

0 comments on commit c51edb8

Please sign in to comment.