mirror of
https://github.com/rectorphp/rector.git
synced 2025-04-16 13:33:13 +02:00
Updated Rector to commit dc580ae1bb540eed78d915db46168b39c1469b42
dc580ae1bb
Fix skip() Rector class, make container forget it comleteely (#4807)
This commit is contained in:
parent
a2d4674549
commit
b8fef75121
@ -3,25 +3,15 @@
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Skipper\SkipCriteriaResolver;
|
||||
|
||||
use PHPStan\Reflection\ReflectionProvider;
|
||||
use Rector\Core\Configuration\Option;
|
||||
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
|
||||
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
|
||||
final class SkippedClassResolver
|
||||
{
|
||||
/**
|
||||
* @readonly
|
||||
* @var \PHPStan\Reflection\ReflectionProvider
|
||||
*/
|
||||
private $reflectionProvider;
|
||||
/**
|
||||
* @var array<string, string[]|null>
|
||||
*/
|
||||
private $skippedClasses = [];
|
||||
public function __construct(ReflectionProvider $reflectionProvider)
|
||||
{
|
||||
$this->reflectionProvider = $reflectionProvider;
|
||||
}
|
||||
/**
|
||||
* @return array<string, string[]|null>
|
||||
*/
|
||||
@ -45,7 +35,8 @@ final class SkippedClassResolver
|
||||
if (!\is_string($key)) {
|
||||
continue;
|
||||
}
|
||||
if (!$this->reflectionProvider->hasClass($key)) {
|
||||
// this only checks for Rector rules, that are always autoloaded
|
||||
if (!\class_exists($key) && !\interface_exists($key)) {
|
||||
continue;
|
||||
}
|
||||
$this->skippedClasses[$key] = $value;
|
||||
|
@ -10,7 +10,6 @@ use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\DependencyInjection\LazyContainerFactory;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\Util\Reflection\PrivatesAccessor;
|
||||
use RectorPrefix202308\Webmozart\Assert\Assert;
|
||||
abstract class AbstractLazyTestCase extends TestCase
|
||||
{
|
||||
/**
|
||||
@ -25,9 +24,7 @@ abstract class AbstractLazyTestCase extends TestCase
|
||||
{
|
||||
$rectorConfig = self::getContainer();
|
||||
foreach ($configFiles as $configFile) {
|
||||
$configClosure = (require $configFile);
|
||||
Assert::isCallable($configClosure);
|
||||
$configClosure($rectorConfig);
|
||||
$rectorConfig->import($configFile);
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '9e19ff6b2fb081799d74a9ef6a4c068c2e7a5a01';
|
||||
public const PACKAGE_VERSION = 'dc580ae1bb540eed78d915db46168b39c1469b42';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-08-17 12:13:08';
|
||||
public const RELEASE_DATE = '2023-08-17 13:11:59';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
30
src/DependencyInjection/Laravel/ContainerMemento.php
Normal file
30
src/DependencyInjection/Laravel/ContainerMemento.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Core\DependencyInjection\Laravel;
|
||||
|
||||
use RectorPrefix202308\Illuminate\Container\Container;
|
||||
use Rector\Core\Util\Reflection\PrivatesAccessor;
|
||||
/**
|
||||
* Helper service to modify Laravel container
|
||||
*/
|
||||
final class ContainerMemento
|
||||
{
|
||||
public static function forgetService(Container $container, string $typeToForget) : void
|
||||
{
|
||||
// 1. remove the service
|
||||
$container->offsetUnset($typeToForget);
|
||||
// 2. remove all tagged rules
|
||||
$privatesAccessor = new PrivatesAccessor();
|
||||
$privatesAccessor->propertyClosure($container, 'tags', static function (array $tags) use($typeToForget) : array {
|
||||
foreach ($tags as $tagName => $taggedClasses) {
|
||||
foreach ($taggedClasses as $key => $taggedClass) {
|
||||
if (\is_a($taggedClass, $typeToForget, \true)) {
|
||||
unset($tags[$tagName][$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return $tags;
|
||||
});
|
||||
}
|
||||
}
|
@ -62,6 +62,7 @@ use Rector\Core\Contract\DependencyInjection\ResetableInterface;
|
||||
use Rector\Core\Contract\Processor\FileProcessorInterface;
|
||||
use Rector\Core\Contract\Rector\PhpRectorInterface;
|
||||
use Rector\Core\Contract\Rector\RectorInterface;
|
||||
use Rector\Core\DependencyInjection\Laravel\ContainerMemento;
|
||||
use Rector\Core\Logging\CurrentRectorProvider;
|
||||
use Rector\Core\Logging\RectorOutput;
|
||||
use Rector\Core\NodeDecorator\CreatedByRuleDecorator;
|
||||
@ -164,6 +165,7 @@ use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
|
||||
use Rector\PostRector\Application\PostFileProcessor;
|
||||
use Rector\RectorGenerator\Command\GenerateCommand;
|
||||
use Rector\RectorGenerator\Command\InitRecipeCommand;
|
||||
use Rector\Skipper\SkipCriteriaResolver\SkippedClassResolver;
|
||||
use Rector\Skipper\Skipper\Skipper;
|
||||
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
|
||||
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
|
||||
@ -264,7 +266,6 @@ final class LazyContainerFactory
|
||||
// make use of https://github.com/symplify/easy-parallel
|
||||
$rectorConfig->singleton(Application::class, static function () : Application {
|
||||
$application = new Application();
|
||||
// @todo inject commands
|
||||
$privatesAccessor = new PrivatesAccessor();
|
||||
$privatesAccessor->propertyClosure($application, 'commands', static function (array $commands) : array {
|
||||
unset($commands['completion']);
|
||||
@ -273,12 +274,12 @@ final class LazyContainerFactory
|
||||
});
|
||||
return $application;
|
||||
});
|
||||
$rectorConfig->singleton(ConsoleApplication::class, ConsoleApplication::class);
|
||||
$rectorConfig->when(ConsoleApplication::class)->needs('$commands')->giveTagged(Command::class);
|
||||
$rectorConfig->singleton(Inflector::class, static function () : Inflector {
|
||||
$inflectorFactory = new InflectorFactory();
|
||||
return $inflectorFactory->build();
|
||||
});
|
||||
$rectorConfig->singleton(ConsoleApplication::class, ConsoleApplication::class);
|
||||
$rectorConfig->when(ConsoleApplication::class)->needs('$commands')->giveTagged(Command::class);
|
||||
$rectorConfig->tag(ProcessCommand::class, Command::class);
|
||||
$rectorConfig->tag(WorkerCommand::class, Command::class);
|
||||
$rectorConfig->tag(SetupCICommand::class, Command::class);
|
||||
@ -392,6 +393,20 @@ final class LazyContainerFactory
|
||||
$this->createPHPStanServices($rectorConfig);
|
||||
// @todo add base node visitors
|
||||
$rectorConfig->when(PhpDocNodeMapper::class)->needs('$phpDocNodeVisitors')->giveTagged(BasePhpDocNodeVisitorInterface::class);
|
||||
/** @param mixed $parameters */
|
||||
$hasForgotten = \false;
|
||||
$rectorConfig->beforeResolving(static function (string $abstract, array $parameters, Container $container) use(&$hasForgotten) : void {
|
||||
// run only once
|
||||
if ($hasForgotten && !\defined('PHPUNIT_COMPOSER_INSTALL')) {
|
||||
return;
|
||||
}
|
||||
$skippedClassResolver = new SkippedClassResolver();
|
||||
$skippedClasses = \array_keys($skippedClassResolver->resolve());
|
||||
foreach ($skippedClasses as $skippedClass) {
|
||||
ContainerMemento::forgetService($container, $skippedClass);
|
||||
}
|
||||
$hasForgotten = \true;
|
||||
});
|
||||
return $rectorConfig;
|
||||
}
|
||||
/**
|
||||
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
||||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa::getLoader();
|
||||
return ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a::getLoader();
|
||||
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
@ -1201,6 +1201,7 @@ return array(
|
||||
'Rector\\Core\\Contract\\Rector\\PhpRectorInterface' => $baseDir . '/src/Contract/Rector/PhpRectorInterface.php',
|
||||
'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\\Laravel\\ContainerMemento' => $baseDir . '/src/DependencyInjection/Laravel/ContainerMemento.php',
|
||||
'Rector\\Core\\DependencyInjection\\LazyContainerFactory' => $baseDir . '/src/DependencyInjection/LazyContainerFactory.php',
|
||||
'Rector\\Core\\DependencyInjection\\RectorContainerFactory' => $baseDir . '/src/DependencyInjection/RectorContainerFactory.php',
|
||||
'Rector\\Core\\Differ\\DefaultDiffer' => $baseDir . '/src/Differ/DefaultDiffer.php',
|
||||
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
@ -2,7 +2,7 @@
|
||||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa
|
||||
class ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
@ -22,17 +22,17 @@ class ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa
|
||||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
@ -4,7 +4,7 @@
|
||||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa
|
||||
class ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
@ -1433,6 +1433,7 @@ class ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa
|
||||
'Rector\\Core\\Contract\\Rector\\PhpRectorInterface' => __DIR__ . '/../..' . '/src/Contract/Rector/PhpRectorInterface.php',
|
||||
'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\\Laravel\\ContainerMemento' => __DIR__ . '/../..' . '/src/DependencyInjection/Laravel/ContainerMemento.php',
|
||||
'Rector\\Core\\DependencyInjection\\LazyContainerFactory' => __DIR__ . '/../..' . '/src/DependencyInjection/LazyContainerFactory.php',
|
||||
'Rector\\Core\\DependencyInjection\\RectorContainerFactory' => __DIR__ . '/../..' . '/src/DependencyInjection/RectorContainerFactory.php',
|
||||
'Rector\\Core\\Differ\\DefaultDiffer' => __DIR__ . '/../..' . '/src/Differ/DefaultDiffer.php',
|
||||
@ -2637,9 +2638,9 @@ class ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa
|
||||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user