Skip to content

Commit

Permalink
Fixed #24975343: Nested list expressions not handled.
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelpichler committed Feb 15, 2012
1 parent 3945b56 commit d124ef0
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 49 deletions.
11 changes: 11 additions & 0 deletions src/main/php/PHP/Depend/Parser.php
Expand Up @@ -1491,6 +1491,11 @@ private function _parseListExpression()
case self::T_PARENTHESIS_CLOSE:
break 2;

case self::T_LIST:
$list->addChild($this->_parseListExpression());
$this->consumeComments();
break;

default:
$list->addChild($this->_parseVariableOrConstantOrPrimaryPrefix());
$this->consumeComments();
Expand Down Expand Up @@ -4133,6 +4138,12 @@ private function _parseVariableOrConstantOrPrimaryPrefix()
case self::T_NAMESPACE:
$node = $this->_parseMemberPrefixOrFunctionPostfix();
break;

default:
throw new PHP_Depend_Parser_UnexpectedTokenException(
$this->tokenizer->next(),
$this->_sourceFile->getFileName()
);
}

return $node;
Expand Down
3 changes: 3 additions & 0 deletions src/site/docx/changes.xml
Expand Up @@ -22,6 +22,9 @@
<action date="4d6a687" dev="mapi" issue="24732243" system="pivotaltracker" type="fix" due-to="Brian Kendig">
pdepend fails on 'const'
</action>
<action date="" dev="mapi" issue="24975343" system="pivotaltracker" type="fix" due-to="bluszcz">
PHP_Depend doesn't handle nested list expressions.
</action>
</release>

<release version="1.0.1"
Expand Down
159 changes: 125 additions & 34 deletions src/test/php/PHP/Depend/Code/ASTListExpressionTest.php
Expand Up @@ -70,48 +70,140 @@
*/
class PHP_Depend_Code_ASTListExpressionTest extends PHP_Depend_Code_ASTNodeTest
{
/**
* testListExpression
*
* @return PHP_Depend_Code_ASTListExpression
* @since 1.0.2
*/
public function testListExpression()
{
$expr = $this->_getFirstListExpressionInFunction();
$this->assertInstanceOf(PHP_Depend_Code_ASTListExpression::CLAZZ, $expr);

return $expr;
}

/**
* Tests the start line value.
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @depends testListExpression
*/
public function testListExpressionHasExpectedStartLine()
public function testListExpressionHasExpectedStartLine($expr)
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$this->assertEquals(4, $stmt->getStartLine());
$this->assertEquals(4, $expr->getStartLine());
}

/**
* Tests the start column value.
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @depends testListExpression
*/
public function testListExpressionHasExpectedStartColumn()
public function testListExpressionHasExpectedStartColumn($expr)
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$this->assertEquals(5, $stmt->getStartColumn());
$this->assertEquals(5, $expr->getStartColumn());
}

/**
* Tests the end line value.
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @depends testListExpression
*/
public function testListExpressionHasExpectedEndLine()
public function testListExpressionHasExpectedEndLine($expr)
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$this->assertEquals(4, $stmt->getEndLine());
$this->assertEquals(4, $expr->getEndLine());
}

/**
* Tests the end column value.
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @depends testListExpression
*/
public function testListExpressionHasExpectedEndColumn($expr)
{
$this->assertEquals(16, $expr->getEndColumn());
}

/**
* testListExpressionWithNestedList
*
* @return PHP_Depend_Code_ASTListExpression
* @since 1.0.2
*/
public function testListExpressionWithNestedList()
{
$expr = $this->_getFirstListExpressionInFunction();
$this->assertInstanceOf(PHP_Depend_Code_ASTListExpression::CLAZZ, $expr);

return $expr;
}

/**
* testListExpressionWithNestedListHasExpectedStartLine
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @since 1.0.2
* @depends testListExpressionWithNestedList
*/
public function testListExpressionHasExpectedEndColumn()
public function testListExpressionWithNestedListHasExpectedStartLine($expr)
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$this->assertEquals(16, $stmt->getEndColumn());
$this->assertEquals(4, $expr->getStartLine());
}

/**
* testListExpressionWithNestedListHasExpectedStartColumn
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @since 1.0.2
* @depends testListExpressionWithNestedList
*/
public function testListExpressionWithNestedListHasExpectedStartColumn($expr)
{
$this->assertEquals(5, $expr->getStartColumn());
}

/**
* testListExpressionWithNestedListHasExpectedEndLine
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @since 1.0.2
* @depends testListExpressionWithNestedList
*/
public function testListExpressionWithNestedListHasExpectedEndLine($expr)
{
$this->assertEquals(4, $expr->getEndLine());
}

/**
* testListExpressionWithNestedListHasExpectedEndColumn
*
* @param PHP_Depend_Code_ASTListExpression $expr
*
* @return void
* @since 1.0.2
* @depends testListExpressionWithNestedList
*/
public function testListExpressionWithNestedListHasExpectedEndColumn($expr)
{
$this->assertEquals(42, $expr->getEndColumn());
}

/**
Expand All @@ -121,8 +213,8 @@ public function testListExpressionHasExpectedEndColumn()
*/
public function testListExpressionSupportsManyVariables()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$vars = $stmt->getChildren();
$expr = $this->_getFirstListExpressionInFunction();
$vars = $expr->getChildren();
$this->assertEquals(3, count($vars));
}

Expand All @@ -133,8 +225,8 @@ public function testListExpressionSupportsManyVariables()
*/
public function testListExpressionSupportsSingleVariable()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$vars = $stmt->getChildren();
$expr = $this->_getFirstListExpressionInFunction();
$vars = $expr->getChildren();
$this->assertEquals(1, count($vars));
}

Expand All @@ -145,8 +237,8 @@ public function testListExpressionSupportsSingleVariable()
*/
public function testListExpressionSupportsExtraCommas()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$vars = $stmt->getChildren();
$expr = $this->_getFirstListExpressionInFunction();
$vars = $expr->getChildren();
$this->assertEquals(3, count($vars));
}

Expand All @@ -157,8 +249,8 @@ public function testListExpressionSupportsExtraCommas()
*/
public function testListExpressionWithComments()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$vars = $stmt->getChildren();
$expr = $this->_getFirstListExpressionInFunction();
$vars = $expr->getChildren();
$this->assertEquals(3, count($vars));
}

Expand All @@ -169,8 +261,8 @@ public function testListExpressionWithComments()
*/
public function testListExpressionWithoutChildExpression()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$vars = $stmt->getChildren();
$expr = $this->_getFirstListExpressionInFunction();
$vars = $expr->getChildren();
$this->assertEquals(0, count($vars));
}

Expand All @@ -181,8 +273,8 @@ public function testListExpressionWithoutChildExpression()
*/
public function testListExpressionWithVariableVariable()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$var = $stmt->getChild(0);
$expr = $this->_getFirstListExpressionInFunction();
$var = $expr->getChild(0);

$this->assertInstanceOf(PHP_Depend_Code_ASTVariableVariable::CLAZZ, $var);
}
Expand All @@ -194,8 +286,8 @@ public function testListExpressionWithVariableVariable()
*/
public function testListExpressionWithCompoundVariable()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$var = $stmt->getChild(0);
$expr = $this->_getFirstListExpressionInFunction();
$var = $expr->getChild(0);

$this->assertInstanceOf(PHP_Depend_Code_ASTCompoundVariable::CLAZZ, $var);
}
Expand All @@ -207,8 +299,8 @@ public function testListExpressionWithCompoundVariable()
*/
public function testListExpressionWithArrayElement()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$var = $stmt->getChild(0);
$expr = $this->_getFirstListExpressionInFunction();
$var = $expr->getChild(0);

$this->assertInstanceOf(PHP_Depend_Code_ASTArrayIndexExpression::CLAZZ, $var);
}
Expand All @@ -220,23 +312,22 @@ public function testListExpressionWithArrayElement()
*/
public function testListExpressionWithObjectProperty()
{
$stmt = $this->_getFirstListExpressionInFunction(__METHOD__);
$var = $stmt->getChild(0);
$expr = $this->_getFirstListExpressionInFunction();
$var = $expr->getChild(0);

$this->assertInstanceOf(PHP_Depend_Code_ASTMemberPrimaryPrefix::CLAZZ, $var);
}

/**
* Returns a node instance for the currently executed test case.
*
* @param string $testCase Name of the calling test case.
*
* @return PHP_Depend_Code_ASTListExpression
*/
private function _getFirstListExpressionInFunction($testCase)
private function _getFirstListExpressionInFunction()
{
return $this->getFirstNodeOfTypeInFunction(
$testCase, PHP_Depend_Code_ASTListExpression::CLAZZ
$this->getCallingTestMethod(),
PHP_Depend_Code_ASTListExpression::CLAZZ
);
}
}
Expand Up @@ -2,4 +2,5 @@
function testListExpressionHasExpectedEndColumn()
{
list($a, $b) = array("a", "b");
var_dump( $a, $b );
}

This file was deleted.

This file was deleted.

This file was deleted.

@@ -0,0 +1,17 @@
<?php
function testListExpressionWithNestedList()
{
list( $a, list( $b, list( $c, $d ) ) ) = array(
'a',
array(
'b',
array(
'c',
'd'
)
)
);

var_dump( $a, $b, $c, $d );
}
testListExpressionWithNestedList();

0 comments on commit d124ef0

Please sign in to comment.