Skip to content

Commit 9662f43

Browse files
committed
File::getMethodProperties(): add new return_type_end_token index to return value
With union types, even non-class return types may consist of multiple tokens, so having access to the stackPtr for the exact end of the return type becomes relevant for sniffs which include fixers. This commit adds a `return_type_end_token` index key to the array return value of the `File::getMethodProperties()` method.
1 parent 457afdf commit 9662f43

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

src/Files/File.php

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,17 +1538,19 @@ public function getMethodParameters($stackPtr)
15381538
* The format of the return value is:
15391539
* <code>
15401540
* array(
1541-
* 'scope' => 'public', // Public, private, or protected
1542-
* 'scope_specified' => true, // TRUE if the scope keyword was found.
1543-
* 'return_type' => '', // The return type of the method.
1544-
* 'return_type_token' => integer, // The stack pointer to the start of the return type
1545-
* // or FALSE if there is no return type.
1546-
* 'nullable_return_type' => false, // TRUE if the return type is preceded by the
1547-
* // nullability operator.
1548-
* 'is_abstract' => false, // TRUE if the abstract keyword was found.
1549-
* 'is_final' => false, // TRUE if the final keyword was found.
1550-
* 'is_static' => false, // TRUE if the static keyword was found.
1551-
* 'has_body' => false, // TRUE if the method has a body
1541+
* 'scope' => 'public', // Public, private, or protected
1542+
* 'scope_specified' => true, // TRUE if the scope keyword was found.
1543+
* 'return_type' => '', // The return type of the method.
1544+
* 'return_type_token' => integer, // The stack pointer to the start of the return type
1545+
* // or FALSE if there is no return type.
1546+
* 'return_type_end_token' => integer, // The stack pointer to the end of the return type
1547+
* // or FALSE if there is no return type.
1548+
* 'nullable_return_type' => false, // TRUE if the return type is preceded by the
1549+
* // nullability operator.
1550+
* 'is_abstract' => false, // TRUE if the abstract keyword was found.
1551+
* 'is_final' => false, // TRUE if the final keyword was found.
1552+
* 'is_static' => false, // TRUE if the static keyword was found.
1553+
* 'has_body' => false, // TRUE if the method has a body
15521554
* );
15531555
* </code>
15541556
*
@@ -1627,6 +1629,7 @@ public function getMethodProperties($stackPtr)
16271629

16281630
$returnType = '';
16291631
$returnTypeToken = false;
1632+
$returnTypeEndToken = false;
16301633
$nullableReturnType = false;
16311634
$hasBody = true;
16321635

@@ -1666,9 +1669,10 @@ public function getMethodProperties($stackPtr)
16661669
$returnTypeToken = $i;
16671670
}
16681671

1669-
$returnType .= $this->tokens[$i]['content'];
1672+
$returnType .= $this->tokens[$i]['content'];
1673+
$returnTypeEndToken = $i;
16701674
}
1671-
}
1675+
}//end for
16721676

16731677
if ($this->tokens[$stackPtr]['code'] === T_FN) {
16741678
$bodyToken = T_FN_ARROW;
@@ -1685,15 +1689,16 @@ public function getMethodProperties($stackPtr)
16851689
}
16861690

16871691
return [
1688-
'scope' => $scope,
1689-
'scope_specified' => $scopeSpecified,
1690-
'return_type' => $returnType,
1691-
'return_type_token' => $returnTypeToken,
1692-
'nullable_return_type' => $nullableReturnType,
1693-
'is_abstract' => $isAbstract,
1694-
'is_final' => $isFinal,
1695-
'is_static' => $isStatic,
1696-
'has_body' => $hasBody,
1692+
'scope' => $scope,
1693+
'scope_specified' => $scopeSpecified,
1694+
'return_type' => $returnType,
1695+
'return_type_token' => $returnTypeToken,
1696+
'return_type_end_token' => $returnTypeEndToken,
1697+
'nullable_return_type' => $nullableReturnType,
1698+
'is_abstract' => $isAbstract,
1699+
'is_final' => $isFinal,
1700+
'is_static' => $isStatic,
1701+
'has_body' => $hasBody,
16971702
];
16981703

16991704
}//end getMethodProperties()

0 commit comments

Comments
 (0)