Skip to content

Commit

Permalink
Merge branch 'master' into const-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Emir Beganović authored Dec 6, 2017
2 parents 2be571f + 6e15e48 commit 1059e0b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/php/PDepend/Source/Language/PHP/AbstractPHPParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
use PDepend\Source\AST\ASTAllocationExpression;
use PDepend\Source\AST\ASTArguments;
use PDepend\Source\AST\ASTArray;
use PDepend\Source\AST\ASTCatchStatement;
use PDepend\Source\AST\ASTClass;
use PDepend\Source\AST\ASTDeclareStatement;
use PDepend\Source\AST\ASTExpression;
Expand Down Expand Up @@ -3273,11 +3274,7 @@ private function parseCatchStatement()
$this->consumeComments();
$this->consumeToken(Tokens::T_PARENTHESIS_OPEN);

$catch->addChild(
$this->builder->buildAstClassOrInterfaceReference(
$this->parseQualifiedName()
)
);
$this->parseCatchExceptionClass($catch);

$this->consumeComments();
$catch->addChild($this->parseVariable());
Expand All @@ -3290,6 +3287,20 @@ private function parseCatchStatement()
return $this->setNodePositionsAndReturn($catch);
}

/**
* This method parses class references in catch statement.
*
* @param \PDepend\Source\AST\ASTCatchStatement $stmt The owning catch statement.
*/
protected function parseCatchExceptionClass(ASTCatchStatement $stmt)
{
$stmt->addChild(
$this->builder->buildAstClassOrInterfaceReference(
$this->parseQualifiedName()
)
);
}

/**
* This method parses a finally-statement.
*
Expand Down
11 changes: 11 additions & 0 deletions src/main/php/PDepend/Source/Language/PHP/PHPParserVersion71.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,15 @@ protected function parseScalarOrCallableTypeHint($image)
return parent::parseScalarOrCallableTypeHint($image);
}

protected function parseCatchExceptionClass(\PDepend\Source\AST\ASTCatchStatement $stmt) {
do {
$repeat = false;
parent::parseCatchExceptionClass($stmt);

if (Tokens::T_BITWISE_OR === $this->tokenizer->peek()) {
$this->consumeToken(Tokens::T_BITWISE_OR);
$repeat = true;
}
} while ($repeat === true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function testConstVisibilityInInterfacePublic()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
Expand All @@ -82,6 +83,7 @@ public function testConstVisibilityInInterfaceProtected()

$this->parseCodeResourceForTest();
}

/**
* @return void
*/
Expand All @@ -95,6 +97,14 @@ public function testConstVisibilityInInterfacePrivate()
$this->parseCodeResourceForTest();
}

/**
* @return void
*/
public function testCatchMultipleExceptionClasses()
{
$this->assertNotNull($this->parseCodeResourceForTest());
}

/**
* @return void
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
function testCatchMultipleExceptionClasses()
{
try {
// do something
} catch (Exception|FooException $e) {}
}

0 comments on commit 1059e0b

Please sign in to comment.