Skip to content

Commit

Permalink
Merge pull request #10713 from weirdan/fix_psalm_type
Browse files Browse the repository at this point in the history
  • Loading branch information
weirdan committed Feb 15, 2024
2 parents fe2c67e + 03fcf68 commit e9dad66
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
Expand Up @@ -78,6 +78,7 @@
use function implode;
use function is_int;
use function is_string;
use function ltrim;
use function preg_match;
use function preg_replace;
use function preg_split;
Expand Down Expand Up @@ -1932,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 @@ -1948,11 +1949,12 @@ 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);
}

$type_string = implode('', $var_line_parts);
$type_string = ltrim($type_string, "* \n\r");
try {
$type_string = CommentAnalyzer::splitDocLine($type_string)[0];
} catch (DocblockParseException $e) {
Expand Down
22 changes: 22 additions & 0 deletions tests/AnnotationTest.php
Expand Up @@ -513,6 +513,28 @@ function example(string $_x) : void {}',
*/
class A {}',
],
'multipeLineGenericArray2' => [
'code' => '<?php
/**
* @psalm-type TRelAlternate =
* list<
* array{
* href: string,
* lang: string
* }
* >
*/
class A {
/** @return TRelAlternate */
public function ret(): array { return []; }
}
$_ = (new A)->ret();
',
'assertions' => [
'$_===' => 'list<array{href: string, lang: string}>',
],
],
'builtInClassInAShape' => [
'code' => '<?php
/**
Expand Down
16 changes: 16 additions & 0 deletions tests/TypeAnnotationTest.php
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 e9dad66

Please sign in to comment.