Skip to content

Commit

Permalink
Fixes phpmd/phpmd#328 with an invalid parser state
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Pichler committed Mar 10, 2016
1 parent a443f77 commit ffe9957
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/main/php/PDepend/Source/AST/AbstractASTCallable.php
Expand Up @@ -284,6 +284,24 @@ public function getReturnClass()
return null;
}

/**
* Tests if this callable has a return class and return <b>true</b> if it is
* configured.
*
* @return boolean
* @since 2.2.4
*/
public function hasReturnClass()
{
if ($this->returnClassReference) {
return true;
}
if (($node = $this->getReturnType()) instanceof ASTClassOrInterfaceReference) {
return true;
}
return false;
}

/**
* @return \PDepend\Source\AST\ASTType
*/
Expand Down
Expand Up @@ -51,6 +51,7 @@
use PDepend\Source\AST\ASTClass;
use PDepend\Source\AST\ASTDeclareStatement;
use PDepend\Source\AST\ASTExpression;
use PDepend\Source\AST\ASTIndexExpression;
use PDepend\Source\AST\ASTInterface;
use PDepend\Source\AST\ASTNode;
use PDepend\Source\AST\ASTStatement;
Expand Down Expand Up @@ -3922,12 +3923,14 @@ private function parseMemberPrimaryPrefix(ASTNode $node)
$tokenType = $this->tokenizer->peek();

switch ($tokenType) {
case Tokens::T_CALLABLE:
/* Fixme */
case Tokens::T_STRING:
$child = $this->parseIdentifier();
$child = $this->parseOptionalIndexExpression($child);

// TODO: Move this in a separate method
if ($child instanceof \PDepend\Source\AST\ASTIndexExpression) {
if ($child instanceof ASTIndexExpression) {
$this->consumeComments();
if (Tokens::T_PARENTHESIS_OPEN === $this->tokenizer->peek()) {
$prefix->addChild($this->parsePropertyPostfix($child));
Expand Down Expand Up @@ -6709,7 +6712,7 @@ private function prepareCallable(AbstractASTCallable $callable)
}

// Stop here if return class already exists.
if ($callable->getReturnClass()) {
if ($callable->hasReturnClass()) {
return;
}

Expand Down

0 comments on commit ffe9957

Please sign in to comment.