Skip to content

Commit

Permalink
add nowdoc
Browse files Browse the repository at this point in the history
stanning

linting, stanning

add visibility

use nowdoc in a few more places
  • Loading branch information
shmax committed Sep 28, 2023
1 parent 0206f1b commit cc41c61
Show file tree
Hide file tree
Showing 3 changed files with 388 additions and 253 deletions.
21 changes: 20 additions & 1 deletion src/Parser/TypeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,12 +944,31 @@ private function parseObjectShapeItem(TokenIterator $tokens): Ast\Type\ObjectSha
$startLine = $tokens->currentTokenLine();
$startIndex = $tokens->currentTokenIndex();

// parse any comments above the item
$comments = [];
while (1) {
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
continue;
} elseif ($tokens->currentTokenType() === Lexer::TOKEN_COMMENT) {
$comments[] = new Ast\Comment($tokens->currentTokenValue(), $tokens->currentTokenLine(), $tokens->currentTokenIndex());
$tokens->next();
} else {
break;
}
}

$key = $this->parseObjectShapeKey($tokens);
$optional = $tokens->tryConsumeTokenType(Lexer::TOKEN_NULLABLE);
$tokens->consumeTokenType(Lexer::TOKEN_COLON);
$value = $this->parse($tokens);

return $this->enrichWithAttributes($tokens, new Ast\Type\ObjectShapeItemNode($key, $optional, $value), $startLine, $startIndex);
return $this->enrichWithAttributes(
$tokens,
new Ast\Type\ObjectShapeItemNode($key, $optional, $value),
$startLine,
$startIndex,
$comments
);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions tests/PHPStan/Parser/TypeParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ public function provideParseData(): array
],
[
'object{
// a is for apple
a: int,
}',
new ObjectShapeNode([
Expand All @@ -1979,6 +1980,9 @@ public function provideParseData(): array
[
'object{
a: int,
/*
* b is for banana
*/
b: string,
}',
new ObjectShapeNode([
Expand Down
Loading

0 comments on commit cc41c61

Please sign in to comment.