Skip to content

Commit

Permalink
Updated Rector to commit dc580ae1bb540eed78d915db46168b39c1469b42
Browse files Browse the repository at this point in the history
rectorphp/rector-src@dc580ae Fix skip() Rector class, make container forget it comleteely (#4807)
  • Loading branch information
TomasVotruba committed Aug 17, 2023
1 parent a2d4674 commit b8fef75
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 30 deletions.
13 changes: 2 additions & 11 deletions packages/Skipper/SkipCriteriaResolver/SkippedClassResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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>
*/
Expand All @@ -45,7 +35,8 @@ public function resolve() : array
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;
Expand Down
5 changes: 1 addition & 4 deletions packages/Testing/PHPUnit/AbstractLazyTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
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
{
/**
Expand All @@ -25,9 +24,7 @@ protected function bootFromConfigFiles(array $configFiles) : void
{
$rectorConfig = self::getContainer();
foreach ($configFiles as $configFile) {
$configClosure = (require $configFile);
Assert::isCallable($configClosure);
$configClosure($rectorConfig);
$rectorConfig->import($configFile);
}
}
/**
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
30 changes: 30 additions & 0 deletions src/DependencyInjection/Laravel/ContainerMemento.php
Original file line number Diff line number Diff line change
@@ -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;
});
}
}
21 changes: 18 additions & 3 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
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;
Expand Down Expand Up @@ -164,6 +165,7 @@
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;
Expand Down Expand Up @@ -264,7 +266,6 @@ public function create() : RectorConfig
// 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']);
Expand All @@ -273,12 +274,12 @@ public function create() : RectorConfig
});
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);
Expand Down Expand Up @@ -392,6 +393,20 @@ public function create() : RectorConfig
$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;
}
/**
Expand Down
2 changes: 1 addition & 1 deletion vendor/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa::getLoader();
return ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a::getLoader();
1 change: 1 addition & 0 deletions vendor/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,7 @@
'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',
Expand Down
10 changes: 5 additions & 5 deletions vendor/composer/autoload_real.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

// autoload_real.php @generated by Composer

class ComposerAutoloaderInit2dac7f3092ddf8fca400f3efe0ae7baa
class ComposerAutoloaderInit09bf9b7ae79c8d3442a2002158653e4a
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
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;
Expand Down
9 changes: 5 additions & 4 deletions vendor/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace Composer\Autoload;

class ComposerStaticInit2dac7f3092ddf8fca400f3efe0ae7baa
class ComposerStaticInit09bf9b7ae79c8d3442a2002158653e4a
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b8fef75

Please sign in to comment.