Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adds a test for array type hint

  • Loading branch information...
commit b08ccefca9d55010a62bb5c4438ea263537dfce3 1 parent 575ff65
@schmittjoh authored
View
30 src/JMS/PhpManipulator/SimultaneousTokenAstStream.php
@@ -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()
@@ -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;
}
View
3  tests/JMS/PhpManipulator/Tests/Fixture/array_typehint.php
@@ -0,0 +1,3 @@
+<?php
+
+function foo(array $foo = array()) { }
View
1  tests/JMS/PhpManipulator/Tests/SimultaneousTokenAndAstStreamTest.php
@@ -33,6 +33,7 @@ public function getRunThroughTests()
array('bitwise_operations.php'),
array('assign_list.php'),
array('refs.php'),
+ array('array_typehint.php'),
);
}
Please sign in to comment.
Something went wrong with that request. Please try again.