Permalink
Browse files

fixes cases where array items where assigned by ref (closes schmittjo…

  • Loading branch information...
1 parent 760e34c commit 575ff6571b67d1d9a3cd1ad9fe716b53e52c365f @schmittjoh committed Dec 3, 2012
View
Oops, something went wrong.
@@ -54,6 +54,15 @@ public function getNodes()
return $this->nodes;
}
+ public function skipUnless($callable)
+ {
+ while ( ! call_user_func($callable, $this->node) && $this->moveNext());
+
+ if (null === $this->node) {
+ throw new \RuntimeException('Matcher could not find any matching node.');
+ }
+ }
+
public function skipUntil($classes)
{
if (!is_array($classes)) {
@@ -87,7 +87,6 @@ class SimultaneousTokenAstStream
T_NEW => 'PHPParser_Node_Expr_New',
'{' => 'JMS\PhpManipulator\PhpParser\BlockNode',
'=' => array('PHPParser_Node_Expr_Assign', 'PHPParser_Node_Expr_AssignRef', 'PHPParser_Node_Expr_AssignList'),
- '&' => 'PHPParser_Node_Expr_BitwiseAnd',
'|' => 'PHPParser_Node_Expr_BitwiseOr',
'^' => 'PHPParser_Node_Expr_BitwiseXor',
'~' => 'PHPParser_Node_Expr_BitwiseNot',
@@ -102,6 +101,7 @@ 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()
@@ -205,6 +205,26 @@ public function __construct()
|| $self->node instanceof \PHPParser_Node_Param) {
return;
}
+
+ // Move to the next Expr_BitwiseAnd, or Expr_ArrayItem which is assigned by ref,
+ // or Arg which is passed by ref.
+ $self->getAstStream()->skipUnless(function(\PHPParser_Node $node) {
+ if ($node instanceof \PHPParser_Node_Expr_BitwiseAnd) {
+ return true;
+ }
+
+ if ($node instanceof \PHPParser_Node_Expr_ArrayItem && $node->byRef) {
+ return true;
+ }
+
+ if ($node instanceof \PHPParser_Node_Arg && $node->byRef) {
+ return true;
+ }
+
+ return false;
+ });
+
+ return;
}
if (isset($translationMap[$char])) {
@@ -10,4 +10,6 @@ function foo(&$foo, &$bar) { }
}
foreach ($foo as &$bar) { }
-foreach ($foo as $name => &$bar) { }
+foreach ($foo as $name => &$bar) { }
+
+$arr = array(&$rs, foo(&$bar));

0 comments on commit 575ff65

Please sign in to comment.