1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #1799 - support trailing commas in object-like docblock types

This commit is contained in:
Brown 2019-06-18 17:47:06 -04:00
parent 1bdd444ce6
commit b12f05185a
2 changed files with 30 additions and 2 deletions

View File

@ -76,7 +76,9 @@ class CommentAnalyzer
$type_start = $offset + $comment->getFilePos();
$type_end = $type_start + strlen($line_parts[0]);
$line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0]));
$line_parts[0] = preg_replace('@^[ \t]*\*@m', '', $line_parts[0]);
$line_parts[0] = preg_replace('/,\n\s+\}/', '}', $line_parts[0]);
$line_parts[0] = str_replace("\n", '', $line_parts[0]);
if ($line_parts[0] === ''
|| ($line_parts[0][0] === '$'
@ -308,7 +310,9 @@ class CommentAnalyzer
$start = $offset + $comment->getFilePos();
$end = $start + strlen($line_parts[0]);
$line_parts[0] = str_replace("\n", '', preg_replace('@^[ \t]*\*@m', '', $line_parts[0]));
$line_parts[0] = preg_replace('@^[ \t]*\*@m', '', $line_parts[0]);
$line_parts[0] = preg_replace('/,\n\s+\}/', '}', $line_parts[0]);
$line_parts[0] = str_replace("\n", '', $line_parts[0]);
if ($line_parts[0] === ''
|| ($line_parts[0][0] === '$'

View File

@ -1014,6 +1014,30 @@ class AnnotationTest extends TestCase
$a->bar();
}'
],
'allowClosingComma' => [
'<?php
/**
* @param array{
* foo: string,
* bar: string,
* baz: array{
* a: int,
* },
* } $foo
*/
function foo(array $foo) : int {
return count($foo);
}
/**
* @var array{
* foo:string,
* bar:string,
* baz:string,
* } $foo
*/
$foo = ["foo" => "", "bar" => "", "baz" => ""];'
],
];
}