Skip to content

Commit cc41c61

Browse files
committed
add nowdoc
stanning linting, stanning add visibility use nowdoc in a few more places
1 parent 0206f1b commit cc41c61

File tree

3 files changed

+388
-253
lines changed

3 files changed

+388
-253
lines changed

src/Parser/TypeParser.php

+20-1
Original file line numberDiff line numberDiff line change
@@ -944,12 +944,31 @@ private function parseObjectShapeItem(TokenIterator $tokens): Ast\Type\ObjectSha
944944
$startLine = $tokens->currentTokenLine();
945945
$startIndex = $tokens->currentTokenIndex();
946946

947+
// parse any comments above the item
948+
$comments = [];
949+
while (1) {
950+
if ($tokens->tryConsumeTokenType(Lexer::TOKEN_PHPDOC_EOL)) {
951+
continue;
952+
} elseif ($tokens->currentTokenType() === Lexer::TOKEN_COMMENT) {
953+
$comments[] = new Ast\Comment($tokens->currentTokenValue(), $tokens->currentTokenLine(), $tokens->currentTokenIndex());
954+
$tokens->next();
955+
} else {
956+
break;
957+
}
958+
}
959+
947960
$key = $this->parseObjectShapeKey($tokens);
948961
$optional = $tokens->tryConsumeTokenType(Lexer::TOKEN_NULLABLE);
949962
$tokens->consumeTokenType(Lexer::TOKEN_COLON);
950963
$value = $this->parse($tokens);
951964

952-
return $this->enrichWithAttributes($tokens, new Ast\Type\ObjectShapeItemNode($key, $optional, $value), $startLine, $startIndex);
965+
return $this->enrichWithAttributes(
966+
$tokens,
967+
new Ast\Type\ObjectShapeItemNode($key, $optional, $value),
968+
$startLine,
969+
$startIndex,
970+
$comments
971+
);
953972
}
954973

955974
/**

tests/PHPStan/Parser/TypeParserTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,7 @@ public function provideParseData(): array
19661966
],
19671967
[
19681968
'object{
1969+
// a is for apple
19691970
a: int,
19701971
}',
19711972
new ObjectShapeNode([
@@ -1979,6 +1980,9 @@ public function provideParseData(): array
19791980
[
19801981
'object{
19811982
a: int,
1983+
/*
1984+
* b is for banana
1985+
*/
19821986
b: string,
19831987
}',
19841988
new ObjectShapeNode([

0 commit comments

Comments
 (0)