mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-11 05:32:23 +00:00
[DX] Make sure provided node types are children of node
This commit is contained in:
parent
f9f62aa311
commit
69adcb274c
|
@ -201,6 +201,7 @@ final class ProcessCommand extends AbstractCommand
|
|||
$this->configuration->setAreAnyPhpRectorsLoaded((bool) $this->rectorNodeTraverser->getPhpRectorCount());
|
||||
|
||||
$this->rectorGuard->ensureSomeRectorsAreRegistered();
|
||||
$this->rectorGuard->ensureGetNodeTypesAreNodes();
|
||||
$this->stubLoader->loadStubs();
|
||||
|
||||
$source = $this->resolvesSourcePaths($input);
|
||||
|
|
11
src/Exception/Rector/InvalidRectorException.php
Normal file
11
src/Exception/Rector/InvalidRectorException.php
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\Exception\Rector;
|
||||
|
||||
use Exception;
|
||||
|
||||
final class InvalidRectorException extends Exception
|
||||
{
|
||||
}
|
|
@ -4,7 +4,9 @@ declare(strict_types=1);
|
|||
|
||||
namespace Rector\Guard;
|
||||
|
||||
use PhpParser\Node;
|
||||
use Rector\Exception\NoRectorsLoadedException;
|
||||
use Rector\Exception\Rector\InvalidRectorException;
|
||||
use Rector\FileSystemRector\FileSystemFileProcessor;
|
||||
use Rector\PhpParser\NodeTraverser\RectorNodeTraverser;
|
||||
|
||||
|
@ -45,4 +47,22 @@ final class RectorGuard
|
|||
PHP_EOL
|
||||
));
|
||||
}
|
||||
|
||||
public function ensureGetNodeTypesAreNodes(): void
|
||||
{
|
||||
foreach ($this->rectorNodeTraverser->getAllPhpRectors() as $phpRector) {
|
||||
foreach ($phpRector->getNodeTypes() as $nodeTypeClass) {
|
||||
if (is_a($nodeTypeClass, Node::class, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
throw new InvalidRectorException(sprintf(
|
||||
'Method "%s::getNodeTypes() provides invalid node class "%s". It must be child of "%s"',
|
||||
get_class($phpRector),
|
||||
$nodeTypeClass,
|
||||
Node::class
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user