phabelVar = 'phabelGeneratorYieldFrom'.\hash('sha256', $file); return parent::shouldRunFile($file); } public function enterNode(YieldFrom $node, Context $ctx) { $var = new Variable($this->phabelVar.($this->phabelCount++)); $assign = new Assign($var, $node->expr); $ifInstanceof = new If_(new Instanceof_(Plugin::callMethod($var, 'valid'), new FullyQualified(\YieldReturnValue::class)), ['stmts' => [new Assign()]]); $while = new While_(new MethodCall($var, new Identifier('valid'))); foreach ($ctx->parents as $node) { if ($node->hasAttribute('currentNodeIndex')) { $ctx->insertBefore($node, $node->expr); } } $generator = $node->expr; return new Node\Expr\Yield_($generator); } }