Skip to content

Commit

Permalink
Merge pull request #10000 from rhertogh/allow_space_before_array_shap…
Browse files Browse the repository at this point in the history
…e_opening_brace

Allow space before array shape opening brace and added unit tests
  • Loading branch information
orklah authored Jul 9, 2023
2 parents b12e4f2 + f7fb2c8 commit 5cb2557
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Psalm/Internal/Analyzer/CommentAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,11 @@ public static function splitDocLine(string $return_block): array
continue;
}

if ($next_char === '{') {
$type .= ' ';
continue;
}

if ($next_char === '|' || $next_char === '&') {
$nexter_char = $i < $l - 2 ? $return_block[$i + 2] : null;

Expand Down
67 changes: 67 additions & 0 deletions tests/CommentAnalyzerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,71 @@ public function testDocblockDescriptionWithVarDescription(): void
$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
* )',
],
],
];
}
}

0 comments on commit 5cb2557

Please sign in to comment.