Skip to content

Commit

Permalink
Allow multiple spaces between type name and type definition
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 15, 2024
1 parent 86224af commit ae21430
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ private static function getTypeAliasesFromCommentLines(
continue;
}

if ($var_line_parts[0] === ' ') {
while (isset($var_line_parts[0]) && $var_line_parts[0] === ' ') {
array_shift($var_line_parts);
}

Expand All @@ -1949,6 +1949,10 @@ private static function getTypeAliasesFromCommentLines(
continue;
}

while (isset($var_line_parts[0]) && $var_line_parts[0] === ' ') {
array_shift($var_line_parts);
}

$type_string = implode('', $var_line_parts);
$type_string = ltrim($type_string, "* \n\r");
try {
Expand Down
16 changes: 16 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,22 @@ public function bar(array $foo): void {}
}
PHP,
],
'typeWithMultipleSpaces' => [
'code' => <<<'PHP'
<?php
/**
* @psalm-type Foo = string
* @psalm-type Bar int
*/
class A {
/**
* @psalm-param Foo $foo
* @psalm-param Bar $bar
*/
public function bar(string $foo, int $bar): void {}
}
PHP,
],
];
}

Expand Down

0 comments on commit ae21430

Please sign in to comment.