Skip to content

Commit

Permalink
File::getMethodProperties(): add new return_type_end_token index to…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
jrfnl committed Nov 2, 2020
1 parent 457afdf commit 9662f43
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1538,17 +1538,19 @@ public function getMethodParameters($stackPtr)
* The format of the return value is:
* <code>
* 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
* );
* </code>
*
Expand Down Expand Up @@ -1627,6 +1629,7 @@ public function getMethodProperties($stackPtr)

$returnType = '';
$returnTypeToken = false;
$returnTypeEndToken = false;
$nullableReturnType = false;
$hasBody = true;

Expand Down Expand Up @@ -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;
Expand All @@ -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()
Expand Down

0 comments on commit 9662f43

Please sign in to comment.