2020-08-24 12:25:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Phabel\Plugin;
|
|
|
|
|
|
|
|
use Phabel\Plugin;
|
2020-08-30 16:58:59 +02:00
|
|
|
use Phabel\Traverser;
|
2020-08-24 12:25:35 +02:00
|
|
|
use PhpParser\Builder\FunctionLike;
|
|
|
|
|
|
|
|
class ReGenerator extends Plugin
|
|
|
|
{
|
|
|
|
const SHOULD_ATTRIBUTE = 'shouldRegenerate';
|
2020-08-30 16:58:59 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Custom traverser.
|
|
|
|
*/
|
|
|
|
private Traverser $traverser;
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->traverser = Traverser::fromPlugin(new ReGeneratorInternal);
|
|
|
|
}
|
2020-08-24 12:25:35 +02:00
|
|
|
public function enter(FunctionLike $function)
|
|
|
|
{
|
|
|
|
if (!$function->getAttribute(self::SHOULD_ATTRIBUTE, false)) {
|
|
|
|
return;
|
|
|
|
}
|
2020-08-30 16:58:59 +02:00
|
|
|
$this->traverser->traverseAst($function);
|
2020-08-24 12:25:35 +02:00
|
|
|
}
|
|
|
|
public function runAfter(): array
|
|
|
|
{
|
|
|
|
return [ArrowClosure::class];
|
|
|
|
}
|
|
|
|
}
|