Updated Rector to commit d772b433c19e2c4ff64befed3ac4517f9645c54b

d772b433c1 [DX] Make rectors public/autowired directly, drop redundant compiler passes (#4324)
This commit is contained in:
Tomas Votruba 2023-06-23 10:41:59 +00:00
parent f8aedc6558
commit fe7f82b7e5
10 changed files with 22 additions and 93 deletions

View File

@ -120,7 +120,7 @@ final class RectorConfig extends ContainerConfigurator
return $value;
});
$servicesConfigurator = $this->getServices();
$rectorService = $servicesConfigurator->set($rectorClass)->call('configure', [$configuration]);
$rectorService = $servicesConfigurator->set($rectorClass)->public()->autowire()->call('configure', [$configuration]);
$this->tagRectorService($rectorService, $rectorClass);
}
/**
@ -131,7 +131,7 @@ final class RectorConfig extends ContainerConfigurator
Assert::classExists($rectorClass);
Assert::isAOf($rectorClass, RectorInterface::class);
$servicesConfigurator = $this->getServices();
$rectorService = $servicesConfigurator->set($rectorClass);
$rectorService = $servicesConfigurator->set($rectorClass)->public()->autowire();
$this->tagRectorService($rectorService, $rectorClass);
}
/**

View File

@ -3,7 +3,6 @@
declare (strict_types=1);
namespace Rector\PHPStanStaticTypeMapper;
use PHPStan\Type\ObjectShapeType;
use PhpParser\Node\ComplexType;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
@ -11,6 +10,7 @@ use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode;
use PHPStan\PhpDocParser\Ast\Type\TypeNode;
use PHPStan\Type\Accessory\HasMethodType;
use PHPStan\Type\ConditionalType;
use PHPStan\Type\ObjectShapeType;
use PHPStan\Type\Type;
use Rector\BetterPhpDocParser\ValueObject\Type\FullyQualifiedIdentifierTypeNode;
use Rector\Core\Exception\NotImplementedYetException;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '914e0e83543d2428d6eec6f49c800f9ed94c351a';
public const PACKAGE_VERSION = 'd772b433c19e2c4ff64befed3ac4517f9645c54b';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-06-23 15:32:02';
public const RELEASE_DATE = '2023-06-23 11:37:09';
/**
* @var int
*/

View File

@ -1,21 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\DependencyInjection\CompilerPass;
use Rector\Core\Contract\Rector\RectorInterface;
use RectorPrefix202306\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use RectorPrefix202306\Symfony\Component\DependencyInjection\ContainerBuilder;
final class AutowireRectorCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder) : void
{
$definitions = $containerBuilder->getDefinitions();
foreach ($definitions as $definition) {
if (!\is_a((string) $definition->getClass(), RectorInterface::class, \true)) {
continue;
}
$definition->setAutowired(\true);
}
}
}

View File

@ -1,23 +0,0 @@
<?php
declare (strict_types=1);
namespace Rector\Core\DependencyInjection\CompilerPass;
use Rector\Core\Contract\Rector\RectorInterface;
use RectorPrefix202306\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use RectorPrefix202306\Symfony\Component\DependencyInjection\ContainerBuilder;
final class MakeRectorsPublicCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $containerBuilder) : void
{
foreach ($containerBuilder->getDefinitions() as $definition) {
if ($definition->getClass() === null) {
continue;
}
if (!\is_a($definition->getClass(), RectorInterface::class, \true)) {
continue;
}
$definition->setPublic(\true);
}
}
}

View File

@ -5,32 +5,24 @@ namespace Rector\Core\Kernel;
use Rector\Core\Config\Loader\ConfigureCallMergingLoaderFactory;
use Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector;
use Rector\Core\DependencyInjection\CompilerPass\AutowireRectorCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\MakeRectorsPublicCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\MergeImportedRectorConfigureCallValuesCompilerPass;
use Rector\Core\DependencyInjection\CompilerPass\RemoveSkippedRectorsCompilerPass;
use RectorPrefix202306\Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use RectorPrefix202306\Symfony\Component\DependencyInjection\ContainerBuilder;
final class ContainerBuilderBuilder
{
/**
* @readonly
* @var \Rector\Core\DependencyInjection\Collector\ConfigureCallValuesCollector
*/
private $configureCallValuesCollector;
public function __construct()
{
$this->configureCallValuesCollector = new ConfigureCallValuesCollector();
}
/**
* @param string[] $configFiles
*/
public function build(array $configFiles) : ContainerBuilder
{
$compilerPasses = $this->createCompilerPasses();
$configureCallMergingLoaderFactory = new ConfigureCallMergingLoaderFactory($this->configureCallValuesCollector);
$configureCallValuesCollector = new ConfigureCallValuesCollector();
$configureCallMergingLoaderFactory = new ConfigureCallMergingLoaderFactory($configureCallValuesCollector);
$containerBuilderFactory = new \Rector\Core\Kernel\ContainerBuilderFactory($configureCallMergingLoaderFactory);
$containerBuilder = $containerBuilderFactory->create($configFiles, $compilerPasses);
$containerBuilder = $containerBuilderFactory->create($configFiles, [
new RemoveSkippedRectorsCompilerPass(),
// adds all merged configure() parameters to rector services
new MergeImportedRectorConfigureCallValuesCompilerPass($configureCallValuesCollector),
]);
// @see https://symfony.com/blog/new-in-symfony-4-4-dependency-injection-improvements-part-1
$containerBuilder->setParameter('container.dumper.inline_factories', \true);
// to fix reincluding files again
@ -38,19 +30,4 @@ final class ContainerBuilderBuilder
$containerBuilder->compile();
return $containerBuilder;
}
/**
* @return CompilerPassInterface[]
*/
private function createCompilerPasses() : array
{
return [
// must run before AutowireArrayParameterCompilerPass, as the autowired array cannot contain removed services
new RemoveSkippedRectorsCompilerPass(),
// autowire Rectors by default (mainly for tests)
new AutowireRectorCompilerPass(),
new MakeRectorsPublicCompilerPass(),
// add all merged arguments of Rector services
new MergeImportedRectorConfigureCallValuesCompilerPass($this->configureCallValuesCollector),
];
}
}

2
vendor/autoload.php vendored
View File

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

View File

@ -1541,8 +1541,6 @@ return array(
'Rector\\Core\\Contract\\Rector\\RectorInterface' => $baseDir . '/src/Contract/Rector/RectorInterface.php',
'Rector\\Core\\Contract\\Rector\\ScopeAwarePhpRectorInterface' => $baseDir . '/src/Contract/Rector/ScopeAwarePhpRectorInterface.php',
'Rector\\Core\\DependencyInjection\\Collector\\ConfigureCallValuesCollector' => $baseDir . '/src/DependencyInjection/Collector/ConfigureCallValuesCollector.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\AutowireRectorCompilerPass' => $baseDir . '/src/DependencyInjection/CompilerPass/AutowireRectorCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\MakeRectorsPublicCompilerPass' => $baseDir . '/src/DependencyInjection/CompilerPass/MakeRectorsPublicCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\MergeImportedRectorConfigureCallValuesCompilerPass' => $baseDir . '/src/DependencyInjection/CompilerPass/MergeImportedRectorConfigureCallValuesCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\RemoveSkippedRectorsCompilerPass' => $baseDir . '/src/DependencyInjection/CompilerPass/RemoveSkippedRectorsCompilerPass.php',
'Rector\\Core\\DependencyInjection\\Loader\\ConfigurableCallValuesCollectingPhpFileLoader' => $baseDir . '/src/DependencyInjection/Loader/ConfigurableCallValuesCollectingPhpFileLoader.php',

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInitc644214e8c6c4d4808faac9044b3b7c4
class ComposerAutoloaderInitf5ea623160b100c5bc96539fc7eae527
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInitc644214e8c6c4d4808faac9044b3b7c4
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInitc644214e8c6c4d4808faac9044b3b7c4', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitf5ea623160b100c5bc96539fc7eae527', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitc644214e8c6c4d4808faac9044b3b7c4', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitf5ea623160b100c5bc96539fc7eae527', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitf5ea623160b100c5bc96539fc7eae527::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitf5ea623160b100c5bc96539fc7eae527::$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 ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4
class ComposerStaticInitf5ea623160b100c5bc96539fc7eae527
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -1792,8 +1792,6 @@ class ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4
'Rector\\Core\\Contract\\Rector\\RectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/RectorInterface.php',
'Rector\\Core\\Contract\\Rector\\ScopeAwarePhpRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/ScopeAwarePhpRectorInterface.php',
'Rector\\Core\\DependencyInjection\\Collector\\ConfigureCallValuesCollector' => __DIR__ . '/../..' . '/src/DependencyInjection/Collector/ConfigureCallValuesCollector.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\AutowireRectorCompilerPass' => __DIR__ . '/../..' . '/src/DependencyInjection/CompilerPass/AutowireRectorCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\MakeRectorsPublicCompilerPass' => __DIR__ . '/../..' . '/src/DependencyInjection/CompilerPass/MakeRectorsPublicCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\MergeImportedRectorConfigureCallValuesCompilerPass' => __DIR__ . '/../..' . '/src/DependencyInjection/CompilerPass/MergeImportedRectorConfigureCallValuesCompilerPass.php',
'Rector\\Core\\DependencyInjection\\CompilerPass\\RemoveSkippedRectorsCompilerPass' => __DIR__ . '/../..' . '/src/DependencyInjection/CompilerPass/RemoveSkippedRectorsCompilerPass.php',
'Rector\\Core\\DependencyInjection\\Loader\\ConfigurableCallValuesCollectingPhpFileLoader' => __DIR__ . '/../..' . '/src/DependencyInjection/Loader/ConfigurableCallValuesCollectingPhpFileLoader.php',
@ -3096,9 +3094,9 @@ class ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitc644214e8c6c4d4808faac9044b3b7c4::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitf5ea623160b100c5bc96539fc7eae527::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitf5ea623160b100c5bc96539fc7eae527::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitf5ea623160b100c5bc96539fc7eae527::$classMap;
}, null, ClassLoader::class);
}