From 9662f431bd95ab253f75d68ea8265981d41edcc6 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 8 Jul 2020 16:06:28 +0200 Subject: [PATCH] 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. --- src/Files/File.php | 49 +++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/Files/File.php b/src/Files/File.php index 8d1f1a8416..d3c799d2ca 100644 --- a/src/Files/File.php +++ b/src/Files/File.php @@ -1538,17 +1538,19 @@ public function getMethodParameters($stackPtr) * The format of the return value is: * * array( - * 'scope' => 'public', // Public, private, or protected - * 'scope_specified' => true, // TRUE if the scope keyword was found. - * 'return_type' => '', // The return type of the method. - * 'return_type_token' => integer, // The stack pointer to the start of the return type - * // or FALSE if there is no return type. - * 'nullable_return_type' => false, // TRUE if the return type is preceded by the - * // nullability operator. - * 'is_abstract' => false, // TRUE if the abstract keyword was found. - * 'is_final' => false, // TRUE if the final keyword was found. - * 'is_static' => false, // TRUE if the static keyword was found. - * 'has_body' => false, // TRUE if the method has a body + * 'scope' => 'public', // Public, private, or protected + * 'scope_specified' => true, // TRUE if the scope keyword was found. + * 'return_type' => '', // The return type of the method. + * 'return_type_token' => integer, // The stack pointer to the start of the return type + * // or FALSE if there is no return type. + * 'return_type_end_token' => integer, // The stack pointer to the end of the return type + * // or FALSE if there is no return type. + * 'nullable_return_type' => false, // TRUE if the return type is preceded by the + * // nullability operator. + * 'is_abstract' => false, // TRUE if the abstract keyword was found. + * 'is_final' => false, // TRUE if the final keyword was found. + * 'is_static' => false, // TRUE if the static keyword was found. + * 'has_body' => false, // TRUE if the method has a body * ); * * @@ -1627,6 +1629,7 @@ public function getMethodProperties($stackPtr) $returnType = ''; $returnTypeToken = false; + $returnTypeEndToken = false; $nullableReturnType = false; $hasBody = true; @@ -1666,9 +1669,10 @@ public function getMethodProperties($stackPtr) $returnTypeToken = $i; } - $returnType .= $this->tokens[$i]['content']; + $returnType .= $this->tokens[$i]['content']; + $returnTypeEndToken = $i; } - } + }//end for if ($this->tokens[$stackPtr]['code'] === T_FN) { $bodyToken = T_FN_ARROW; @@ -1685,15 +1689,16 @@ public function getMethodProperties($stackPtr) } return [ - 'scope' => $scope, - 'scope_specified' => $scopeSpecified, - 'return_type' => $returnType, - 'return_type_token' => $returnTypeToken, - 'nullable_return_type' => $nullableReturnType, - 'is_abstract' => $isAbstract, - 'is_final' => $isFinal, - 'is_static' => $isStatic, - 'has_body' => $hasBody, + 'scope' => $scope, + 'scope_specified' => $scopeSpecified, + 'return_type' => $returnType, + 'return_type_token' => $returnTypeToken, + 'return_type_end_token' => $returnTypeEndToken, + 'nullable_return_type' => $nullableReturnType, + 'is_abstract' => $isAbstract, + 'is_final' => $isFinal, + 'is_static' => $isStatic, + 'has_body' => $hasBody, ]; }//end getMethodProperties()