mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 20:00:50 +00:00
907c0dcefa
2d9fc68b65
Bump Rector deps (#38)
57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\NetteToSymfony\Rector\Interface_;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\Node\Stmt\Interface_;
|
|
use Rector\Core\Rector\AbstractRector;
|
|
use Rector\NetteToSymfony\NodeAnalyzer\NetteControlFactoryInterfaceAnalyzer;
|
|
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
|
|
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
|
|
/**
|
|
* @see \Rector\NetteToSymfony\Tests\Rector\Interface_\DeleteFactoryInterfaceRector\DeleteFactoryInterfaceFileSystemRectorTest
|
|
*/
|
|
final class DeleteFactoryInterfaceRector extends \Rector\Core\Rector\AbstractRector
|
|
{
|
|
/**
|
|
* @var \Rector\NetteToSymfony\NodeAnalyzer\NetteControlFactoryInterfaceAnalyzer
|
|
*/
|
|
private $netteControlFactoryInterfaceAnalyzer;
|
|
public function __construct(\Rector\NetteToSymfony\NodeAnalyzer\NetteControlFactoryInterfaceAnalyzer $netteControlFactoryInterfaceAnalyzer)
|
|
{
|
|
$this->netteControlFactoryInterfaceAnalyzer = $netteControlFactoryInterfaceAnalyzer;
|
|
}
|
|
public function getRuleDefinition() : \Symplify\RuleDocGenerator\ValueObject\RuleDefinition
|
|
{
|
|
return new \Symplify\RuleDocGenerator\ValueObject\RuleDefinition('Interface factories are not needed in Symfony. Clear constructor injection is used instead', [new \Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample(<<<'CODE_SAMPLE'
|
|
interface SomeControlFactoryInterface
|
|
{
|
|
public function create();
|
|
}
|
|
CODE_SAMPLE
|
|
, <<<'CODE_SAMPLE'
|
|
CODE_SAMPLE
|
|
)]);
|
|
}
|
|
/**
|
|
* @return array<class-string<Node>>
|
|
*/
|
|
public function getNodeTypes() : array
|
|
{
|
|
return [\PhpParser\Node\Stmt\Interface_::class];
|
|
}
|
|
/**
|
|
* @param Interface_ $node
|
|
*/
|
|
public function refactor(\PhpParser\Node $node) : ?\PhpParser\Node
|
|
{
|
|
if (!$this->netteControlFactoryInterfaceAnalyzer->isComponentFactoryInterface($node)) {
|
|
return null;
|
|
}
|
|
$smartFileInfo = $this->file->getSmartFileInfo();
|
|
$this->removedAndAddedFilesCollector->removeFile($smartFileInfo);
|
|
return null;
|
|
}
|
|
}
|