Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: vimeo/psalm
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 5.22.0
Choose a base ref
...
head repository: vimeo/psalm
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 5.22.1
Choose a head ref
  • 3 commits
  • 3 files changed
  • 2 contributors

Commits on Feb 15, 2024

  1. Improve parsing of psalm-type

    danog authored and weirdan committed Feb 15, 2024
    Copy the full SHA
    893b60e View commit details
  2. Allow multiple spaces between type name and type definition

    weirdan committed Feb 15, 2024
    Copy the full SHA
    03fcf68 View commit details
  3. Merge pull request #10713 from weirdan/fix_psalm_type

    weirdan authored Feb 15, 2024
    Copy the full SHA
    e9dad66 View commit details
Showing with 42 additions and 2 deletions.
  1. +4 −2 src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php
  2. +22 −0 tests/AnnotationTest.php
  3. +16 −0 tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
@@ -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;
@@ -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);
}

@@ -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) {
22 changes: 22 additions & 0 deletions tests/AnnotationTest.php
Original file line number Diff line number Diff line change
@@ -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
/**
16 changes: 16 additions & 0 deletions tests/TypeAnnotationTest.php
Original file line number Diff line number Diff line change
@@ -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,
],
];
}