Updated Rector to commit 6f1f2676d45d2c514d567bdb52cfbb06c8b3db53

6f1f2676d4 [DX] Various injection and tests details improvement (#4702)
This commit is contained in:
Tomas Votruba 2023-08-07 12:16:32 +00:00
parent ad2ad2a097
commit a68d89f0cc
10 changed files with 370 additions and 53 deletions

View File

@ -130,7 +130,7 @@ return static function (RectorConfig $rectorConfig) : void {
foreach ($extensionConfigFiles as $extensionConfigFile) {
$rectorConfig->import($extensionConfigFile);
}
$services->load('Rector\\Core\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/Rector', __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', __DIR__ . '/../src/Exception', __DIR__ . '/../src/DependencyInjection/CompilerPass', __DIR__ . '/../src/DependencyInjection/Loader', __DIR__ . '/../src/Kernel', __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Bootstrap', __DIR__ . '/../src/Enum', __DIR__ . '/../src/functions', __DIR__ . '/../src/PhpParser/Node/CustomNode', __DIR__ . '/../src/PhpParser/ValueObject', __DIR__ . '/../src/PHPStan/NodeVisitor', __DIR__ . '/../src/constants.php']);
$services->load('Rector\\Core\\', __DIR__ . '/../src')->exclude([__DIR__ . '/../src/Rector', __DIR__ . '/../src/Console/Style/RectorConsoleOutputStyle.php', __DIR__ . '/../src/Exception', __DIR__ . '/../src/DependencyInjection/CompilerPass', __DIR__ . '/../src/DependencyInjection/Loader', __DIR__ . '/../src/DependencyInjection/LazyContainerFactory.php', __DIR__ . '/../src/Kernel', __DIR__ . '/../src/ValueObject', __DIR__ . '/../src/Bootstrap', __DIR__ . '/../src/Enum', __DIR__ . '/../src/functions', __DIR__ . '/../src/PhpParser/Node/CustomNode', __DIR__ . '/../src/PhpParser/ValueObject', __DIR__ . '/../src/PHPStan/NodeVisitor', __DIR__ . '/../src/constants.php']);
$services->set(ConsoleApplication::class)->arg('$commands', tagged_iterator(Command::class));
$services->alias(Application::class, ConsoleApplication::class);
$services->set(SimpleCallableNodeTraverser::class);

View File

@ -0,0 +1,238 @@
<?php
declare (strict_types=1);
namespace Rector\Config;
use RectorPrefix202308\Illuminate\Container\Container;
use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\Configuration\ValueObjectInliner;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\Contract\Rector\RectorInterface;
use Rector\Core\Exception\ShouldNotHappenException;
use Rector\Core\ValueObject\PhpVersion;
use RectorPrefix202308\Webmozart\Assert\Assert;
/**
* @api soon be used as public API
*/
final class LazyRectorConfig extends Container
{
/**
* @param string[] $paths
*/
public function paths(array $paths) : void
{
Assert::allString($paths);
SimpleParameterProvider::setParameter(Option::PATHS, $paths);
}
/**
* @param string[] $sets
*/
public function sets(array $sets) : void
{
Assert::allString($sets);
foreach ($sets as $set) {
Assert::fileExists($set);
$this->import($set);
}
}
public function disableParallel() : void
{
SimpleParameterProvider::setParameter(Option::PARALLEL, \false);
}
public function parallel(int $seconds = 120, int $maxNumberOfProcess = 16, int $jobSize = 20) : void
{
SimpleParameterProvider::setParameter(Option::PARALLEL, \true);
SimpleParameterProvider::setParameter(Option::PARALLEL_JOB_TIMEOUT_IN_SECONDS, $seconds);
SimpleParameterProvider::setParameter(Option::PARALLEL_MAX_NUMBER_OF_PROCESSES, $maxNumberOfProcess);
SimpleParameterProvider::setParameter(Option::PARALLEL_JOB_SIZE, $jobSize);
}
public function noDiffs() : void
{
SimpleParameterProvider::setParameter(Option::NO_DIFFS, \true);
}
public function memoryLimit(string $memoryLimit) : void
{
SimpleParameterProvider::setParameter(Option::MEMORY_LIMIT, $memoryLimit);
}
/**
* @param array<int|string, mixed> $criteria
*/
public function skip(array $criteria) : void
{
SimpleParameterProvider::addParameter(Option::SKIP, $criteria);
}
public function removeUnusedImports(bool $removeUnusedImports = \true) : void
{
SimpleParameterProvider::setParameter(Option::REMOVE_UNUSED_IMPORTS, $removeUnusedImports);
}
public function importNames(bool $importNames = \true, bool $importDocBlockNames = \true) : void
{
SimpleParameterProvider::setParameter(Option::AUTO_IMPORT_NAMES, $importNames);
SimpleParameterProvider::setParameter(Option::AUTO_IMPORT_DOC_BLOCK_NAMES, $importDocBlockNames);
}
public function importShortClasses(bool $importShortClasses = \true) : void
{
SimpleParameterProvider::setParameter(Option::IMPORT_SHORT_CLASSES, $importShortClasses);
}
/**
* Set PHPStan custom config to load extensions and custom configuration to Rector.
* By default, the "phpstan.neon" path is used.
*/
public function phpstanConfig(string $filePath) : void
{
Assert::fileExists($filePath);
SimpleParameterProvider::setParameter(Option::PHPSTAN_FOR_RECTOR_PATH, $filePath);
}
/**
* @param class-string<ConfigurableRectorInterface&RectorInterface> $rectorClass
* @param mixed[] $configuration
*/
public function ruleWithConfiguration(string $rectorClass, array $configuration) : void
{
Assert::classExists($rectorClass);
Assert::isAOf($rectorClass, RectorInterface::class);
Assert::isAOf($rectorClass, ConfigurableRectorInterface::class);
// decorate with value object inliner so Symfony understands, see https://getrector.com/blog/2020/09/07/how-to-inline-value-object-in-symfony-php-config
\array_walk_recursive($configuration, static function (&$value) {
if (\is_object($value)) {
$value = ValueObjectInliner::inline($value);
}
return $value;
});
$this->singleton($rectorClass);
$this->extend($rectorClass, function (ConfigurableRectorInterface $configurableRector) use($configuration) {
$configurableRector->configure($configuration);
});
$this->tagRectorService($rectorClass);
}
/**
* @param class-string<RectorInterface> $rectorClass
*/
public function rule(string $rectorClass) : void
{
Assert::classExists($rectorClass);
Assert::isAOf($rectorClass, RectorInterface::class);
$this->singleton($rectorClass);
$this->tagRectorService($rectorClass);
}
public function import(string $setFilePath) : void
{
$self = $this;
$callable = (require $setFilePath);
Assert::isCallable($callable);
/** @var callable(Container $container): void $callable */
$callable($self);
}
/**
* @param array<class-string<RectorInterface>> $rectorClasses
*/
public function rules(array $rectorClasses) : void
{
Assert::allString($rectorClasses);
$duplicatedRectorClasses = $this->resolveDuplicatedValues($rectorClasses);
if ($duplicatedRectorClasses !== []) {
throw new ShouldNotHappenException('Following rules are registered twice: ' . \implode(', ', $duplicatedRectorClasses));
}
foreach ($rectorClasses as $rectorClass) {
$this->rule($rectorClass);
}
}
/**
* @param PhpVersion::* $phpVersion
*/
public function phpVersion(int $phpVersion) : void
{
SimpleParameterProvider::setParameter(Option::PHP_VERSION_FEATURES, $phpVersion);
}
/**
* @param string[] $autoloadPaths
*/
public function autoloadPaths(array $autoloadPaths) : void
{
Assert::allString($autoloadPaths);
SimpleParameterProvider::setParameter(Option::AUTOLOAD_PATHS, $autoloadPaths);
}
/**
* @param string[] $bootstrapFiles
*/
public function bootstrapFiles(array $bootstrapFiles) : void
{
Assert::allString($bootstrapFiles);
SimpleParameterProvider::setParameter(Option::BOOTSTRAP_FILES, $bootstrapFiles);
}
public function symfonyContainerXml(string $filePath) : void
{
SimpleParameterProvider::setParameter(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, $filePath);
}
public function symfonyContainerPhp(string $filePath) : void
{
SimpleParameterProvider::setParameter(Option::SYMFONY_CONTAINER_PHP_PATH_PARAMETER, $filePath);
}
/**
* @param string[] $extensions
*/
public function fileExtensions(array $extensions) : void
{
Assert::allString($extensions);
SimpleParameterProvider::setParameter(Option::FILE_EXTENSIONS, $extensions);
}
public function cacheDirectory(string $directoryPath) : void
{
// cache directory path is created via mkdir in CacheFactory
// when not exists, so no need to validate $directoryPath is a directory
SimpleParameterProvider::setParameter(Option::CACHE_DIR, $directoryPath);
}
public function containerCacheDirectory(string $directoryPath) : void
{
// container cache directory path must be a directory on the first place
Assert::directory($directoryPath);
SimpleParameterProvider::setParameter(Option::CONTAINER_CACHE_DIRECTORY, $directoryPath);
}
/**
* @param class-string<CacheStorageInterface> $cacheClass
*/
public function cacheClass(string $cacheClass) : void
{
Assert::isAOf($cacheClass, CacheStorageInterface::class);
SimpleParameterProvider::setParameter(Option::CACHE_CLASS, $cacheClass);
}
/**
* @see https://github.com/nikic/PHP-Parser/issues/723#issuecomment-712401963
*/
public function indent(string $character, int $count) : void
{
SimpleParameterProvider::setParameter(Option::INDENT_CHAR, $character);
SimpleParameterProvider::setParameter(Option::INDENT_SIZE, $count);
}
/**
* @param string[] $values
* @return string[]
*/
private function resolveDuplicatedValues(array $values) : array
{
$counted = \array_count_values($values);
$duplicates = [];
foreach ($counted as $value => $count) {
if ($count > 1) {
$duplicates[] = $value;
}
}
return \array_unique($duplicates);
}
/**
* @param class-string<RectorInterface|PhpRectorInterface|NonPhpRectorInterface> $rectorClass
*/
private function tagRectorService(string $rectorClass) : void
{
$this->tag($rectorClass, RectorInterface::class);
if (\is_a($rectorClass, PhpRectorInterface::class, \true)) {
$this->tag($rectorClass, PhpRectorInterface::class);
} elseif (\is_a($rectorClass, NonPhpRectorInterface::class, \true)) {
$this->tag($rectorClass, NonPhpRectorInterface::class);
}
}
}

View File

@ -8,7 +8,6 @@ use RectorPrefix202308\Nette\Utils\FileSystem;
use RectorPrefix202308\Nette\Utils\Strings;
use PHPStan\Analyser\NodeScopeResolver;
use PHPUnit\Framework\ExpectationFailedException;
use RectorPrefix202308\Psr\Container\ContainerInterface;
use Rector\Core\Application\ApplicationFileProcessor;
use Rector\Core\Autoloading\AdditionalAutoloader;
use Rector\Core\Autoloading\BootstrapFilesIncluder;
@ -24,10 +23,6 @@ use Rector\Testing\Fixture\FixtureFileUpdater;
use Rector\Testing\Fixture\FixtureSplitter;
abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractTestCase implements RectorTestInterface
{
/**
* @var \Psr\Container\ContainerInterface|null
*/
protected static $allRectorContainer;
/**
* @var \Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider
*/

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '77258018af10a7c23477831e0eab49dd7c0b2bfe';
public const PACKAGE_VERSION = '6f1f2676d45d2c514d567bdb52cfbb06c8b3db53';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-07 10:59:16';
public const RELEASE_DATE = '2023-08-07 12:12:02';
/**
* @var int
*/

View File

@ -26,9 +26,42 @@ use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayP
use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\ChangesReporting\Contract\Output\OutputFormatterInterface;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipper;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\AliasClassNameImportSkipVoter;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\ClassLikeNameClassNameImportSkipVoter;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\FullyQualifiedNameClassNameImportSkipVoter;
use Rector\CodingStyle\ClassNameImport\ClassNameImportSkipVoter\UsesClassNameImportSkipVoter;
use Rector\CodingStyle\Contract\ClassNameImport\ClassNameImportSkipVoterInterface;
use Rector\Config\LazyRectorConfig;
use Rector\Config\RectorConfig;
use Rector\Core\Application\ApplicationFileProcessor;
use Rector\Core\Application\ChangedNodeScopeRefresher;
use Rector\Core\Application\FileProcessor\PhpFileProcessor;
use Rector\Core\Configuration\CurrentNodeProvider;
use Rector\Core\Console\Output\RectorOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyle;
use Rector\Core\Console\Style\RectorConsoleOutputStyleFactory;
use Rector\Core\Contract\Console\OutputStyleInterface;
use Rector\Core\Contract\Processor\FileProcessorInterface;
use Rector\Core\Contract\Rector\NonPhpRectorInterface;
use Rector\Core\Contract\Rector\PhpRectorInterface;
use Rector\Core\FileSystem\FilePathHelper;
use Rector\Core\Logging\CurrentRectorProvider;
use Rector\Core\NodeDecorator\CreatedByRuleDecorator;
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\NodeFactory;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\ProcessAnalyzer\RectifiedAnalyzer;
use Rector\Core\Provider\CurrentFileProvider;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\Core\ValueObjectFactory\Application\FileFactory;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeNameResolver\NodeNameResolver\ClassConstFetchNameResolver;
@ -69,6 +102,7 @@ use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\NameNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StaticVariableNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\NodeVisitor\StmtKeyNodeVisitor;
use Rector\NodeTypeResolver\PHPStan\Scope\PHPStanNodeScopeResolver;
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
use Rector\PhpAttribute\AnnotationToAttributeMapper;
use Rector\PhpAttribute\AnnotationToAttributeMapper\ArrayAnnotationToAttributeMapper;
use Rector\PhpAttribute\AnnotationToAttributeMapper\ArrayItemNodeAnnotationToAttributeMapper;
@ -79,6 +113,7 @@ use Rector\PhpAttribute\AnnotationToAttributeMapper\DoctrineAnnotationAnnotation
use Rector\PhpAttribute\AnnotationToAttributeMapper\StringAnnotationToAttributeMapper;
use Rector\PhpAttribute\AnnotationToAttributeMapper\StringNodeAnnotationToAttributeMapper;
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryLiteralStringTypeMapper;
@ -115,6 +150,7 @@ use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\TypeWithClassNameTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
use Rector\Skipper\Skipper\Skipper;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
@ -153,6 +189,10 @@ final class LazyContainerFactory
* @var array<class-string<PhpDocTypeMapperInterface>>
*/
private const PHPDOC_TYPE_MAPPER_CLASSES = [IdentifierTypeMapper::class, IntersectionTypeMapper::class, NullableTypeMapper::class, UnionTypeMapper::class];
/**
* @var array<class-string<ClassNameImportSkipVoterInterface>>
*/
private const CLASS_NAME_IMPORT_SKIPPER_CLASSES = [AliasClassNameImportSkipVoter::class, ClassLikeNameClassNameImportSkipVoter::class, FullyQualifiedNameClassNameImportSkipVoter::class, UsesClassNameImportSkipVoter::class];
/**
* @var array<class-string<TypeMapperInterface>>
*/
@ -161,6 +201,10 @@ final class LazyContainerFactory
* @var array<class-string<PhpDocNodeDecoratorInterface>>
*/
private const PHP_DOC_NODE_DECORATOR_CLASSES = [ConstExprClassNameDecorator::class, DoctrineAnnotationDecorator::class];
/**
* @var array<class-string<OutputFormatterInterface>>
*/
private const OUTPUT_FORMATTER_CLASSES = [ConsoleOutputFormatter::class, JsonOutputFormatter::class];
/**
* @var array<class-string<NodeTypeResolverInterface>>
*/
@ -174,12 +218,24 @@ final class LazyContainerFactory
*/
public function create() : Container
{
$container = new Container();
$lazyRectorConfig = new LazyRectorConfig();
// setup base parameters - from RectorConfig
SimpleParameterProvider::setParameter(Option::CACHE_DIR, \sys_get_temp_dir() . '/rector_cached_files');
SimpleParameterProvider::setParameter(Option::CONTAINER_CACHE_DIRECTORY, \sys_get_temp_dir());
SimpleParameterProvider::setParameter(Option::INDENT_SIZE, 4);
$container->singleton(Application::class, static function () : Application {
// make use of https://github.com/symplify/easy-parallel
// $rectorConfig->import(EasyParallelConfig::FILE_PATH);
$lazyRectorConfig->paths([]);
$lazyRectorConfig->skip([]);
$lazyRectorConfig->autoloadPaths([]);
$lazyRectorConfig->bootstrapFiles([]);
$lazyRectorConfig->parallel(120, 16, 20);
// to avoid autoimporting out of the box
$lazyRectorConfig->importNames(\false, \false);
$lazyRectorConfig->removeUnusedImports(\false);
$lazyRectorConfig->importShortClasses();
$lazyRectorConfig->indent(' ', 4);
$lazyRectorConfig->fileExtensions(['php']);
$lazyRectorConfig->cacheDirectory(\sys_get_temp_dir() . '/rector_cached_files');
$lazyRectorConfig->containerCacheDirectory(\sys_get_temp_dir());
$lazyRectorConfig->singleton(Application::class, static function () : Application {
$application = new Application();
// @todo inject commands
$privatesAccessor = new PrivatesAccessor();
@ -190,61 +246,84 @@ final class LazyContainerFactory
});
return $application;
});
$container->singleton(Inflector::class, static function () : Inflector {
$lazyRectorConfig->singleton(Inflector::class, static function () : Inflector {
$inflectorFactory = new InflectorFactory();
return $inflectorFactory->build();
});
$lazyRectorConfig->singleton(OutputStyleInterface::class, RectorOutputStyle::class);
$lazyRectorConfig->singleton(PhpFileProcessor::class);
$lazyRectorConfig->tag(PhpFileProcessor::class, FileProcessorInterface::class);
$lazyRectorConfig->singleton(NonPhpFileProcessor::class);
$lazyRectorConfig->tag(NonPhpFileProcessor::class, FileProcessorInterface::class);
$lazyRectorConfig->when(NonPhpFileProcessor::class)->needs('$nonPhpRectors')->giveTagged(NonPhpRectorInterface::class);
$lazyRectorConfig->when(ApplicationFileProcessor::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class);
$lazyRectorConfig->when(FileFactory::class)->needs('$fileProcessors')->giveTagged(FileProcessorInterface::class);
$lazyRectorConfig->when(RectorNodeTraverser::class)->needs('$phpRectors')->giveTagged(PhpRectorInterface::class);
$lazyRectorConfig->singleton(RectorConsoleOutputStyle::class, function (Container $container) : RectorConsoleOutputStyle {
$rectorConsoleOutputStyleFactory = $container->make(RectorConsoleOutputStyleFactory::class);
return $rectorConsoleOutputStyleFactory->create();
});
$lazyRectorConfig->when(ClassNameImportSkipper::class)->needs('$classNameImportSkipVoters')->giveTagged(ClassNameImportSkipVoterInterface::class);
$lazyRectorConfig->singleton(DynamicSourceLocatorProvider::class, function (Container $container) : DynamicSourceLocatorProvider {
$phpStanServicesFactory = $container->make(PHPStanServicesFactory::class);
return $phpStanServicesFactory->createDynamicSourceLocatorProvider();
});
// caching
$container->singleton(Cache::class, static function (Container $container) : Cache {
$lazyRectorConfig->singleton(Cache::class, static function (Container $container) : Cache {
/** @var CacheFactory $cacheFactory */
$cacheFactory = $container->make(CacheFactory::class);
return $cacheFactory->create();
});
// tagged services
$container->when(BetterPhpDocParser::class)->needs('$phpDocNodeDecorators')->giveTagged(PhpDocNodeDecoratorInterface::class);
$container->when(PHPStanStaticTypeMapper::class)->needs('$typeMappers')->giveTagged(TypeMapperInterface::class);
$container->when(PhpDocTypeMapper::class)->needs('$phpDocTypeMappers')->giveTagged(PhpDocTypeMapperInterface::class);
$container->when(PhpParserNodeMapper::class)->needs('$phpParserNodeMappers')->giveTagged(PhpParserNodeMapperInterface::class);
$container->when(NodeTypeResolver::class)->needs('$nodeTypeResolvers')->giveTagged(NodeTypeResolverInterface::class);
$lazyRectorConfig->when(BetterPhpDocParser::class)->needs('$phpDocNodeDecorators')->giveTagged(PhpDocNodeDecoratorInterface::class);
$lazyRectorConfig->when(PHPStanStaticTypeMapper::class)->needs('$typeMappers')->giveTagged(TypeMapperInterface::class);
$lazyRectorConfig->when(PhpDocTypeMapper::class)->needs('$phpDocTypeMappers')->giveTagged(PhpDocTypeMapperInterface::class);
$lazyRectorConfig->when(PhpParserNodeMapper::class)->needs('$phpParserNodeMappers')->giveTagged(PhpParserNodeMapperInterface::class);
$lazyRectorConfig->when(NodeTypeResolver::class)->needs('$nodeTypeResolvers')->giveTagged(NodeTypeResolverInterface::class);
// node name resolvers
$container->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class);
$this->registerTagged($container, self::PHP_PARSER_NODE_MAPPER_CLASSES, PhpParserNodeMapperInterface::class);
$this->registerTagged($container, self::PHP_DOC_NODE_DECORATOR_CLASSES, PhpDocNodeDecoratorInterface::class);
$this->registerTagged($container, self::TYPE_MAPPER_CLASSES, TypeMapperInterface::class);
$this->registerTagged($container, self::PHPDOC_TYPE_MAPPER_CLASSES, PhpDocTypeMapperInterface::class);
$this->registerTagged($container, self::NODE_NAME_RESOLVER_CLASSES, NodeNameResolverInterface::class);
$this->registerTagged($container, self::NODE_TYPE_RESOLVER_CLASSES, NodeTypeResolverInterface::class);
$this->registerTagged($container, self::ANNOTATION_TO_ATTRIBUTE_MAPPER_CLASSES, AnnotationToAttributeMapperInterface::class);
$container->when(AnnotationToAttributeMapper::class)->needs('$annotationToAttributeMappers')->giveTagged(AnnotationToAttributeMapperInterface::class);
$lazyRectorConfig->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class);
$lazyRectorConfig->afterResolving(AbstractRector::class, function (AbstractRector $rector, Container $container) {
$rector->autowire($container->make(NodeNameResolver::class), $container->make(NodeTypeResolver::class), $container->make(SimpleCallableNodeTraverser::class), $container->make(NodeFactory::class), $container->make(PhpDocInfoFactory::class), $container->make(StaticTypeMapper::class), $container->make(CurrentRectorProvider::class), $container->make(CurrentNodeProvider::class), $container->make(Skipper::class), $container->make(ValueResolver::class), $container->make(BetterNodeFinder::class), $container->make(NodeComparator::class), $container->make(CurrentFileProvider::class), $container->make(RectifiedAnalyzer::class), $container->make(CreatedByRuleDecorator::class), $container->make(ChangedNodeScopeRefresher::class), $container->make(RectorOutputStyle::class), $container->make(FilePathHelper::class));
});
$this->registerTagged($lazyRectorConfig, self::PHP_PARSER_NODE_MAPPER_CLASSES, PhpParserNodeMapperInterface::class);
$this->registerTagged($lazyRectorConfig, self::PHP_DOC_NODE_DECORATOR_CLASSES, PhpDocNodeDecoratorInterface::class);
$this->registerTagged($lazyRectorConfig, self::TYPE_MAPPER_CLASSES, TypeMapperInterface::class);
$this->registerTagged($lazyRectorConfig, self::PHPDOC_TYPE_MAPPER_CLASSES, PhpDocTypeMapperInterface::class);
$this->registerTagged($lazyRectorConfig, self::NODE_NAME_RESOLVER_CLASSES, NodeNameResolverInterface::class);
$this->registerTagged($lazyRectorConfig, self::NODE_TYPE_RESOLVER_CLASSES, NodeTypeResolverInterface::class);
$this->registerTagged($lazyRectorConfig, self::OUTPUT_FORMATTER_CLASSES, OutputFormatterInterface::class);
$this->registerTagged($lazyRectorConfig, self::CLASS_NAME_IMPORT_SKIPPER_CLASSES, ClassNameImportSkipVoterInterface::class);
$this->registerTagged($lazyRectorConfig, self::ANNOTATION_TO_ATTRIBUTE_MAPPER_CLASSES, AnnotationToAttributeMapperInterface::class);
$lazyRectorConfig->when(AnnotationToAttributeMapper::class)->needs('$annotationToAttributeMappers')->giveTagged(AnnotationToAttributeMapperInterface::class);
// #[Required]-like setter
$container->afterResolving(ArrayAnnotationToAttributeMapper::class, static function (ArrayAnnotationToAttributeMapper $arrayAnnotationToAttributeMapper, Container $container) : void {
$lazyRectorConfig->afterResolving(ArrayAnnotationToAttributeMapper::class, static function (ArrayAnnotationToAttributeMapper $arrayAnnotationToAttributeMapper, Container $container) : void {
$annotationToAttributesMapper = $container->make(AnnotationToAttributeMapper::class);
$arrayAnnotationToAttributeMapper->autowire($annotationToAttributesMapper);
});
$container->afterResolving(ArrayItemNodeAnnotationToAttributeMapper::class, static function (ArrayItemNodeAnnotationToAttributeMapper $arrayItemNodeAnnotationToAttributeMapper, Container $container) : void {
$lazyRectorConfig->afterResolving(ArrayItemNodeAnnotationToAttributeMapper::class, static function (ArrayItemNodeAnnotationToAttributeMapper $arrayItemNodeAnnotationToAttributeMapper, Container $container) : void {
$annotationToAttributeMapper = $container->make(AnnotationToAttributeMapper::class);
$arrayItemNodeAnnotationToAttributeMapper->autowire($annotationToAttributeMapper);
});
$container->afterResolving(NameScopeFactory::class, static function (NameScopeFactory $nameScopeFactory, Container $container) : void {
$lazyRectorConfig->afterResolving(NameScopeFactory::class, static function (NameScopeFactory $nameScopeFactory, Container $container) : void {
$nameScopeFactory->autowire($container->make(PhpDocInfoFactory::class), $container->make(StaticTypeMapper::class));
});
$container->afterResolving(ArrayTypeMapper::class, static function (ArrayTypeMapper $arrayTypeMapper, Container $container) : void {
$lazyRectorConfig->afterResolving(ArrayTypeMapper::class, static function (ArrayTypeMapper $arrayTypeMapper, Container $container) : void {
$arrayTypeMapper->autowire($container->make(PHPStanStaticTypeMapper::class));
});
$container->afterResolving(PlainValueParser::class, static function (PlainValueParser $plainValueParser, Container $container) : void {
$lazyRectorConfig->afterResolving(PlainValueParser::class, static function (PlainValueParser $plainValueParser, Container $container) : void {
$plainValueParser->autowire($container->make(StaticDoctrineAnnotationParser::class), $container->make(ArrayParser::class));
});
$container->singleton(Parser::class, static function (Container $container) {
$lazyRectorConfig->singleton(Parser::class, static function (Container $container) {
$phpstanServiceFactory = $container->make(PHPStanServicesFactory::class);
return $phpstanServiceFactory->createPHPStanParser();
});
$container->when(PHPStanNodeScopeResolver::class)->needs('$nodeVisitors')->giveTagged(ScopeResolverNodeVisitorInterface::class);
$this->registerTagged($container, self::SCOPE_RESOLVER_NODE_VISITOR_CLASSES, ScopeResolverNodeVisitorInterface::class);
$lazyRectorConfig->when(PHPStanNodeScopeResolver::class)->needs('$nodeVisitors')->giveTagged(ScopeResolverNodeVisitorInterface::class);
$this->registerTagged($lazyRectorConfig, self::SCOPE_RESOLVER_NODE_VISITOR_CLASSES, ScopeResolverNodeVisitorInterface::class);
// phpstan factory
$this->createPHPStanServices($container);
$this->createPHPStanServices($lazyRectorConfig);
// @todo add base node visitors
$container->when(PhpDocNodeMapper::class)->needs('$phpDocNodeVisitors')->giveTagged(BasePhpDocNodeVisitorInterface::class);
return $container;
$lazyRectorConfig->when(PhpDocNodeMapper::class)->needs('$phpDocNodeVisitors')->giveTagged(BasePhpDocNodeVisitorInterface::class);
return $lazyRectorConfig;
}
/**
* @param array<class-string> $classes
@ -258,12 +337,13 @@ final class LazyContainerFactory
$container->tag($class, $tagInterface);
}
}
private function createPHPStanServices(Container $container) : void
private function createPHPStanServices(LazyRectorConfig $container) : void
{
$container->singleton(ReflectionProvider::class, static function (Container $container) : ReflectionProvider {
$phpstanServiceFactory = $container->make(PHPStanServicesFactory::class);
return $phpstanServiceFactory->createReflectionProvider();
});
// @todo make generic
$container->singleton(Parser::class, static function (Container $container) {
$phpstanServiceFactory = $container->make(PHPStanServicesFactory::class);
return $phpstanServiceFactory->createPHPStanParser();

View File

@ -4,6 +4,7 @@ declare (strict_types=1);
namespace Rector\Core\ValueObject;
use Rector\ChangesReporting\Output\ConsoleOutputFormatter;
use RectorPrefix202308\Webmozart\Assert\Assert;
final class Configuration
{
/**
@ -96,6 +97,7 @@ final class Configuration
*/
public function getFileExtensions() : array
{
Assert::notEmpty($this->fileExtensions);
return $this->fileExtensions;
}
/**

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInita4d07eec2414baf8f8ca642d6f63e446::getLoader();
return ComposerAutoloaderInit15960fb16ad252b4078490560622a6c0::getLoader();

View File

@ -1490,6 +1490,7 @@ return array(
'Rector\\Comments\\NodeDocBlock\\DocBlockUpdater' => $baseDir . '/packages/Comments/NodeDocBlock/DocBlockUpdater.php',
'Rector\\Comments\\NodeTraverser\\CommentRemovingNodeTraverser' => $baseDir . '/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php',
'Rector\\Comments\\NodeVisitor\\CommentRemovingNodeVisitor' => $baseDir . '/packages/Comments/NodeVisitor/CommentRemovingNodeVisitor.php',
'Rector\\Config\\LazyRectorConfig' => $baseDir . '/packages/Config/LazyRectorConfig.php',
'Rector\\Config\\RectorConfig' => $baseDir . '/packages/Config/RectorConfig.php',
'Rector\\Core\\Application\\ApplicationFileProcessor' => $baseDir . '/src/Application/ApplicationFileProcessor.php',
'Rector\\Core\\Application\\ChangedNodeScopeRefresher' => $baseDir . '/src/Application/ChangedNodeScopeRefresher.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInita4d07eec2414baf8f8ca642d6f63e446
class ComposerAutoloaderInit15960fb16ad252b4078490560622a6c0
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInita4d07eec2414baf8f8ca642d6f63e446
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInita4d07eec2414baf8f8ca642d6f63e446', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit15960fb16ad252b4078490560622a6c0', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInita4d07eec2414baf8f8ca642d6f63e446', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit15960fb16ad252b4078490560622a6c0', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit15960fb16ad252b4078490560622a6c0::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInit15960fb16ad252b4078490560622a6c0::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446
class ComposerStaticInit15960fb16ad252b4078490560622a6c0
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1744,6 +1744,7 @@ class ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446
'Rector\\Comments\\NodeDocBlock\\DocBlockUpdater' => __DIR__ . '/../..' . '/packages/Comments/NodeDocBlock/DocBlockUpdater.php',
'Rector\\Comments\\NodeTraverser\\CommentRemovingNodeTraverser' => __DIR__ . '/../..' . '/packages/Comments/NodeTraverser/CommentRemovingNodeTraverser.php',
'Rector\\Comments\\NodeVisitor\\CommentRemovingNodeVisitor' => __DIR__ . '/../..' . '/packages/Comments/NodeVisitor/CommentRemovingNodeVisitor.php',
'Rector\\Config\\LazyRectorConfig' => __DIR__ . '/../..' . '/packages/Config/LazyRectorConfig.php',
'Rector\\Config\\RectorConfig' => __DIR__ . '/../..' . '/packages/Config/RectorConfig.php',
'Rector\\Core\\Application\\ApplicationFileProcessor' => __DIR__ . '/../..' . '/src/Application/ApplicationFileProcessor.php',
'Rector\\Core\\Application\\ChangedNodeScopeRefresher' => __DIR__ . '/../..' . '/src/Application/ChangedNodeScopeRefresher.php',
@ -3011,9 +3012,9 @@ class ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInita4d07eec2414baf8f8ca642d6f63e446::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit15960fb16ad252b4078490560622a6c0::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit15960fb16ad252b4078490560622a6c0::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit15960fb16ad252b4078490560622a6c0::$classMap;
}, null, ClassLoader::class);
}