1
0
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:
orklah 2023-07-09 15:10:01 +02:00 committed by GitHub
commit 5cb2557410
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 0 deletions

View File

@ -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;

View File

@ -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
* )',
],
],
];
}
}