@@ -691,7 +691,7 @@ private function parseClassDeclaration($parentNode) : Node {
691
691
return $ classNode ;
692
692
}
693
693
694
- private function parseClassMembers ($ parentNode ) : Node {
694
+ private function parseClassMembers ($ parentNode ) : ClassMembersNode {
695
695
$ classMembers = new ClassMembersNode ();
696
696
$ classMembers ->openBrace = $ this ->eat1 (TokenKind::OpenBraceToken);
697
697
$ classMembers ->classMemberDeclarations = $ this ->parseList ($ classMembers , ParseContext::ClassMembers);
@@ -804,7 +804,7 @@ private function parseAttributeGroups($parentNode): array
804
804
}
805
805
806
806
/**
807
- * @return DelimitedList\AttributeElementList
807
+ * @return DelimitedList\AttributeElementList|null
808
808
*/
809
809
private function parseAttributeElementList (AttributeGroup $ parentNode ) {
810
810
return $ this ->parseDelimitedList (
@@ -1638,13 +1638,14 @@ private function isParameterStartFn() {
1638
1638
}
1639
1639
1640
1640
/**
1641
- * @param string $className (name of subclass of DelimitedList)
1641
+ * @template TDelimitedList of DelimitedList
1642
+ * @param class-string<TDelimitedList> $className (name of subclass of DelimitedList)
1642
1643
* @param int|int[] $delimiter
1643
1644
* @param callable $isElementStartFn
1644
1645
* @param callable $parseElementFn
1645
1646
* @param Node $parentNode
1646
1647
* @param bool $allowEmptyElements
1647
- * @return DelimitedList |null instance of $className
1648
+ * @return TDelimitedList |null instance of $className
1648
1649
*/
1649
1650
private function parseDelimitedList ($ className , $ delimiter , $ isElementStartFn , $ parseElementFn , $ parentNode , $ allowEmptyElements = false ) {
1650
1651
// TODO consider allowing empty delimiter to be more tolerant
@@ -1994,7 +1995,7 @@ private function parseWhileStatement($parentNode) {
1994
1995
/**
1995
1996
* @param Node $parentNode
1996
1997
* @param bool $force
1997
- * @return Node |MissingToken|array - The expression, or a missing token, or (if $force) an array containing a missed and skipped token
1998
+ * @return Expression |MissingToken|array - The expression, or a missing token, or (if $force) an array containing a missed and skipped token
1998
1999
*/
1999
2000
private function parseExpression ($ parentNode , $ force = false ) {
2000
2001
$ token = $ this ->getCurrentToken ();
@@ -2020,7 +2021,7 @@ private function parseExpressionFn() {
2020
2021
2021
2022
/**
2022
2023
* @param Node $parentNode
2023
- * @return Expression
2024
+ * @return UnaryExpression|MissingToken|Variable|ThrowExpression
2024
2025
*/
2025
2026
private function parseUnaryExpressionOrHigher ($ parentNode ) {
2026
2027
$ token = $ this ->getCurrentToken ();
@@ -3212,9 +3213,16 @@ private function parseMemberAccessExpression($expression):MemberAccessExpression
3212
3213
private function parseScopedPropertyAccessExpression ($ expression , $ fallbackParentNode ): ScopedPropertyAccessExpression {
3213
3214
$ scopedPropertyAccessExpression = new ScopedPropertyAccessExpression ();
3214
3215
$ scopedPropertyAccessExpression ->parent = $ expression ->parent ?? $ fallbackParentNode ;
3216
+
3215
3217
if ($ expression instanceof Node) {
3216
3218
$ expression ->parent = $ scopedPropertyAccessExpression ;
3217
- $ scopedPropertyAccessExpression ->scopeResolutionQualifier = $ expression ; // TODO ensure always a Node
3219
+
3220
+ // scopeResolutionQualifier does not accept `Node` but
3221
+ // `Expression|QualifiedName|Token`. I'm not sure if we can depend
3222
+ // on that being the case.
3223
+ //
3224
+ // @phpstan-ignore-next-line
3225
+ $ scopedPropertyAccessExpression ->scopeResolutionQualifier = $ expression ;
3218
3226
}
3219
3227
3220
3228
$ scopedPropertyAccessExpression ->doubleColon = $ this ->eat1 (TokenKind::ColonColonToken);
@@ -3362,18 +3370,18 @@ private function parseClassConstDeclaration($parentNode, $modifiers) {
3362
3370
}
3363
3371
3364
3372
private function parseEnumCaseDeclaration ($ parentNode ) {
3365
- $ classConstDeclaration = new EnumCaseDeclaration ();
3366
- $ classConstDeclaration ->parent = $ parentNode ;
3367
- $ classConstDeclaration ->caseKeyword = $ this ->eat1 (TokenKind::CaseKeyword);
3368
- $ classConstDeclaration ->name = $ this ->eat ($ this ->nameOrKeywordOrReservedWordTokens );
3369
- $ classConstDeclaration ->equalsToken = $ this ->eatOptional1 (TokenKind::EqualsToken);
3370
- if ($ classConstDeclaration ->equalsToken !== null ) {
3373
+ $ enumCaseDeclaration = new EnumCaseDeclaration ();
3374
+ $ enumCaseDeclaration ->parent = $ parentNode ;
3375
+ $ enumCaseDeclaration ->caseKeyword = $ this ->eat1 (TokenKind::CaseKeyword);
3376
+ $ enumCaseDeclaration ->name = $ this ->eat ($ this ->nameOrKeywordOrReservedWordTokens );
3377
+ $ enumCaseDeclaration ->equalsToken = $ this ->eatOptional1 (TokenKind::EqualsToken);
3378
+ if ($ enumCaseDeclaration ->equalsToken !== null ) {
3371
3379
// TODO add post-parse rule that checks for invalid assignments
3372
- $ classConstDeclaration ->assignment = $ this ->parseExpression ($ classConstDeclaration );
3380
+ $ enumCaseDeclaration ->assignment = $ this ->parseExpression ($ enumCaseDeclaration );
3373
3381
}
3374
- $ classConstDeclaration ->semicolon = $ this ->eat1 (TokenKind::SemicolonToken);
3382
+ $ enumCaseDeclaration ->semicolon = $ this ->eat1 (TokenKind::SemicolonToken);
3375
3383
3376
- return $ classConstDeclaration ;
3384
+ return $ enumCaseDeclaration ;
3377
3385
}
3378
3386
3379
3387
/**
@@ -3446,7 +3454,7 @@ private function parseQualifiedNameCatchList($parentNode) {
3446
3454
return $ result ;
3447
3455
}
3448
3456
3449
- private function parseInterfaceDeclaration ($ parentNode ) {
3457
+ private function parseInterfaceDeclaration ($ parentNode ): InterfaceDeclaration {
3450
3458
$ interfaceDeclaration = new InterfaceDeclaration (); // TODO verify not nested
3451
3459
$ interfaceDeclaration ->parent = $ parentNode ;
3452
3460
$ interfaceDeclaration ->interfaceKeyword = $ this ->eat1 (TokenKind::InterfaceKeyword);
@@ -3456,7 +3464,7 @@ private function parseInterfaceDeclaration($parentNode) {
3456
3464
return $ interfaceDeclaration ;
3457
3465
}
3458
3466
3459
- private function parseInterfaceMembers ($ parentNode ) : Node {
3467
+ private function parseInterfaceMembers ($ parentNode ) : InterfaceMembers {
3460
3468
$ interfaceMembers = new InterfaceMembers ();
3461
3469
$ interfaceMembers ->openBrace = $ this ->eat1 (TokenKind::OpenBraceToken);
3462
3470
$ interfaceMembers ->interfaceMemberDeclarations = $ this ->parseList ($ interfaceMembers , ParseContext::InterfaceMembers);
0 commit comments