mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Merge pull request #10000 from rhertogh/allow_space_before_array_shape_opening_brace
Allow space before array shape opening brace and added unit tests
This commit is contained in:
commit
5cb2557410
@ -346,6 +346,11 @@ class CommentAnalyzer
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($next_char === '{') {
|
||||
$type .= ' ';
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($next_char === '|' || $next_char === '&') {
|
||||
$nexter_char = $i < $l - 2 ? $return_block[$i + 2] : null;
|
||||
|
||||
|
@ -75,4 +75,71 @@ class CommentAnalyzerTest extends BaseTestCase
|
||||
$comment_docblock = CommentAnalyzer::getTypeFromComment($php_parser_doc, new FileScanner('somefile.php', 'somefile.php', false), new Aliases);
|
||||
$this->assertSame('Use a string', $comment_docblock[0]->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providerSplitDocLine
|
||||
* @param string[] $expected
|
||||
*/
|
||||
public function testSplitDocLine(string $doc_line, array $expected): void
|
||||
{
|
||||
$this->assertSame($expected, CommentAnalyzer::splitDocLine($doc_line));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<array-key, array{doc_line: string, expected: string[]}>
|
||||
*/
|
||||
public function providerSplitDocLine(): iterable
|
||||
{
|
||||
return [
|
||||
'typeWithVar' => [
|
||||
'doc_line' =>
|
||||
'TArray $array',
|
||||
'expected' => [
|
||||
'TArray',
|
||||
'$array',
|
||||
],
|
||||
],
|
||||
'arrayShape' => [
|
||||
'doc_line' =>
|
||||
'array{
|
||||
* a: int,
|
||||
* b: string,
|
||||
* }',
|
||||
'expected' => [
|
||||
'array{
|
||||
* a: int,
|
||||
* b: string,
|
||||
* }',
|
||||
],
|
||||
],
|
||||
'arrayShapeWithSpace' => [
|
||||
'doc_line' =>
|
||||
'array {
|
||||
* a: int,
|
||||
* b: string,
|
||||
* }',
|
||||
'expected' => [
|
||||
'array {
|
||||
* a: int,
|
||||
* b: string,
|
||||
* }',
|
||||
],
|
||||
],
|
||||
'func_num_args' => [
|
||||
'doc_line' =>
|
||||
'(
|
||||
* func_num_args() is 1
|
||||
* ? array{dirname: string, basename: string, extension?: string, filename: string}
|
||||
* : string
|
||||
* )',
|
||||
'expected' => [
|
||||
'(
|
||||
* func_num_args() is 1
|
||||
* ? array{dirname: string, basename: string, extension?: string, filename: string}
|
||||
* : string
|
||||
* )',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user