Skip to content

Commit

Permalink
adds a test for array type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
schmittjoh committed Dec 4, 2012
1 parent 575ff65 commit b08ccef
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/JMS/PhpManipulator/SimultaneousTokenAstStream.php
Expand Up @@ -101,7 +101,6 @@ class SimultaneousTokenAstStream
T_CONST => array('PHPParser_Node_Stmt_ClassConst', 'PHPParser_Node_Stmt_Const'),
T_LNUMBER => 'PHPParser_Node_Scalar_LNumber',
T_DNUMBER => 'PHPParser_Node_Scalar_DNumber',
T_ARRAY => 'PHPParser_Node_Expr_Array',
);

public function __construct()
Expand All @@ -128,10 +127,31 @@ public function __construct()
return;
}

// For T_VARIABLE that is related to a catch statement, we also
// bail out as there again is no dedicated node for it.
if ($token->matches(T_VARIABLE)
&& $astStream->node instanceof \PHPParser_Node_Stmt_Catch) {
if ($token->matches(T_VARIABLE)) {
// For T_VARIABLE that is related to a catch statement, we also
// bail out as there again is no dedicated node for it.
if ($astStream->node instanceof \PHPParser_Node_Stmt_Catch) {
return;
}

if ($astStream->node instanceof \PHPParser_Node_Param && $astStream->node->type === 'array') {
return;
}
}

if ($token->matches(T_ARRAY)) {
$astStream->skipUnless(function(\PHPParser_Node $n) {
if ($n instanceof \PHPParser_Node_Expr_Array) {
return true;
}

if ($n instanceof \PHPParser_Node_Param && $n->type === 'array') {
return true;
}

return false;
});

return;
}

Expand Down
3 changes: 3 additions & 0 deletions tests/JMS/PhpManipulator/Tests/Fixture/array_typehint.php
@@ -0,0 +1,3 @@
<?php

function foo(array $foo = array()) { }
Expand Up @@ -33,6 +33,7 @@ public function getRunThroughTests()
array('bitwise_operations.php'),
array('assign_list.php'),
array('refs.php'),
array('array_typehint.php'),
);
}

Expand Down

0 comments on commit b08ccef

Please sign in to comment.