[NodeTraverser] Apply array param autowire

This commit is contained in:
Tomas Votruba 2018-10-06 12:32:19 +08:00
parent 3073942c8a
commit 318f5b30f8
4 changed files with 22 additions and 21 deletions

View File

@ -52,18 +52,6 @@ final class NodeTypeResolver
}
}
private function addPerNodeTypeResolver(PerNodeTypeResolverInterface $perNodeTypeResolver): void
{
foreach ($perNodeTypeResolver->getNodeClasses() as $nodeClass) {
$this->perNodeTypeResolvers[$nodeClass] = $perNodeTypeResolver;
}
// in-code setter injection to drop CompilerPass requirement for 3rd party package install
if ($perNodeTypeResolver instanceof NodeTypeResolverAwareInterface) {
$perNodeTypeResolver->setNodeTypeResolver($this);
}
}
/**
* @return string[]
*/
@ -88,6 +76,18 @@ final class NodeTypeResolver
return $types;
}
private function addPerNodeTypeResolver(PerNodeTypeResolverInterface $perNodeTypeResolver): void
{
foreach ($perNodeTypeResolver->getNodeClasses() as $nodeClass) {
$this->perNodeTypeResolvers[$nodeClass] = $perNodeTypeResolver;
}
// in-code setter injection to drop CompilerPass requirement for 3rd party package install
if ($perNodeTypeResolver instanceof NodeTypeResolverAwareInterface) {
$perNodeTypeResolver->setNodeTypeResolver($this);
}
}
/**
* @return string[]
*/

View File

@ -88,6 +88,9 @@ parameters:
- '#In method "Rector\\Node\\NodeFactory::createArray", parameter \$items can be type-hinted to "array"#'
- '#In method "Rector\\Builder\\StatementGlue::addStatementToClassBeforeTypes", parameter \$types type is "array". Please provide a \@param annotation to further specify the type of the array. For instance: \@param int\[\] \$types#'
# not really needed, empty
- '#Rector\\NodeTraverser\\RectorNodeTraverser::__construct\(\) does not call parent constructor from PhpParser\\NodeTraverser#'
services:
-
class: Symplify\PHPStanExtensions\Type\SplFileInfoTolerantDynamicMethodReturnTypeExtension

View File

@ -7,10 +7,15 @@ use Rector\Contract\Rector\PhpRectorInterface;
final class RectorNodeTraverser extends NodeTraverser
{
public function addRector(PhpRectorInterface $phpRector): void
/**
* @param PhpRectorInterface[] $phpRectors
*/
public function __construct(array $phpRectors = [])
{
foreach ($phpRectors as $phpRector) {
$this->addVisitor($phpRector);
}
}
public function getRectorCount(): int
{

View File

@ -8,10 +8,3 @@ imports:
parameters:
exclude_paths: []
autoload_paths: []
# see https://github.com/symplify/packagebuilder#collect-services-in-short-configs
collectors:
-
main_type: 'Rector\NodeTraverser\RectorNodeTraverser'
collected_type: 'Rector\Contract\Rector\PhpRectorInterface'
add_method: 'addRector'