phabel/src/Plugin/Amp/YieldReturnDetector.php

33 lines
709 B
PHP
Raw Normal View History

2020-08-03 21:31:32 +02:00
<?php
namespace Spatie\Php7to5\NodeVisitors;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
class YieldReturnDetector extends NodeVisitorAbstract
{
protected $hasYield = [];
/**
* {@inheritdoc}
*/
public function enterNode(Node $node)
{
if ($node instanceof Node\FunctionLike) {
$this->hasYield []= $node;
}
if ($node instanceof Node\Expr\Yield_ ||
$node instanceof Node\Expr\YieldFrom
) {
2020-08-09 13:49:19 +02:00
\end($this->hasYield)->hasYield = true;
2020-08-03 21:31:32 +02:00
}
}
public function leaveNode(Node $node)
{
if ($node instanceof Node\FunctionLike) {
2020-08-09 13:49:19 +02:00
\array_pop($this->hasYield);
2020-08-03 21:31:32 +02:00
}
}
}