Skip to content

Commit

Permalink
Updated Rector to commit 3a048f6f6a6614a46eea06abffb7324b15fdc9dc
Browse files Browse the repository at this point in the history
rectorphp/rector-src@3a048f6 [DX] Make use of Laravel container in few tests - step #4 (#4681)
  • Loading branch information
TomasVotruba committed Aug 6, 2023
1 parent 11c3d62 commit b4217dc
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 16 deletions.
14 changes: 10 additions & 4 deletions packages/Testing/PHPUnit/AbstractLazyTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
declare (strict_types=1);
namespace Rector\Testing\PHPUnit;

use RectorPrefix202308\Illuminate\Container\Container;
use PHPUnit\Framework\TestCase;
use Rector\Core\DependencyInjection\LazyContainerFactory;
abstract class AbstractLazyTestCase extends TestCase
{
/**
* @var \Illuminate\Container\Container|null
*/
private static $container;
/**
* @template TType as object
* @param class-string<TType> $class
* @return TType
*/
protected function make(string $class) : object
{
// @todo cache container
$lazyContainerFactory = new LazyContainerFactory();
$container = $lazyContainerFactory->create();
return $container->make($class);
if (!self::$container instanceof Container) {
$lazyContainerFactory = new LazyContainerFactory();
self::$container = $lazyContainerFactory->create();
}
return self::$container->make($class);
}
}
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 = '3f89bdbe3e71edc532a9d0bb33845e6a2478ec4c';
public const PACKAGE_VERSION = '3a048f6f6a6614a46eea06abffb7324b15fdc9dc';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-08-06 16:48:50';
public const RELEASE_DATE = '2023-08-06 17:18:41';
/**
* @var int
*/
Expand Down
67 changes: 67 additions & 0 deletions src/DependencyInjection/LazyContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@
use PHPStan\Reflection\ReflectionProvider;
use Rector\BetterPhpDocParser\Contract\BasePhpDocNodeVisitorInterface;
use Rector\BetterPhpDocParser\Contract\PhpDocParser\PhpDocNodeDecoratorInterface;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocNodeMapper;
use Rector\BetterPhpDocParser\PhpDocParser\BetterPhpDocParser;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\CodingStyle\ClassNameImport\ShortNameResolver;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Core\PhpParser\ClassLikeAstResolver;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\NodeNameResolver\Contract\NodeNameResolverInterface;
use Rector\NodeNameResolver\NodeNameResolver;
Expand Down Expand Up @@ -62,11 +66,52 @@
use Rector\PhpAttribute\Contract\AnnotationToAttributeMapperInterface;
use Rector\PHPStanStaticTypeMapper\Contract\TypeMapperInterface;
use Rector\PHPStanStaticTypeMapper\PHPStanStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryLiteralStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryNonEmptyStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryNonFalsyStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\AccessoryNumericStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ArrayTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\BooleanTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\CallableTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ClassStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ClosureTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConditionalTypeForParameterMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ConditionalTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\FloatTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\GenericClassStringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasMethodTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasOffsetValueTypeTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\HasPropertyTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\IntegerTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\IterableTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\MixedTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\NeverTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\NonEmptyArrayTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\NullTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ObjectWithoutClassTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\OversizedArrayTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ParentStaticTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ResourceTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\SelfObjectTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StrictMixedTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\StringTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\ThisTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\TypeWithClassNameTypeMapper;
use Rector\PHPStanStaticTypeMapper\TypeMapper\VoidTypeMapper;
use Rector\StaticTypeMapper\Contract\PhpDocParser\PhpDocTypeMapperInterface;
use Rector\StaticTypeMapper\Contract\PhpParser\PhpParserNodeMapperInterface;
use Rector\StaticTypeMapper\Mapper\PhpParserNodeMapper;
use Rector\StaticTypeMapper\Naming\NameScopeFactory;
use Rector\StaticTypeMapper\PhpDoc\PhpDocTypeMapper;
use Rector\StaticTypeMapper\PhpDocParser\IdentifierTypeMapper;
use Rector\StaticTypeMapper\PhpDocParser\IntersectionTypeMapper;
use Rector\StaticTypeMapper\PhpDocParser\NullableTypeMapper;
use Rector\StaticTypeMapper\PhpDocParser\UnionTypeMapper;
use Rector\StaticTypeMapper\StaticTypeMapper;
use RectorPrefix202308\Symfony\Component\Console\Application;
use RectorPrefix202308\Webmozart\Assert\Assert;
final class LazyContainerFactory
{
/**
Expand All @@ -81,6 +126,14 @@ final class LazyContainerFactory
* @var array<class-string<ScopeResolverNodeVisitorInterface>>
*/
private const SCOPE_RESOLVER_NODE_VISITOR_CLASSES = [ArgNodeVisitor::class, AssignedToNodeVisitor::class, ByRefReturnNodeVisitor::class, ByRefVariableNodeVisitor::class, ContextNodeVisitor::class, GlobalVariableNodeVisitor::class, NameNodeVisitor::class, StaticVariableNodeVisitor::class, StmtKeyNodeVisitor::class];
/**
* @var array<class-string<PhpDocTypeMapperInterface>>
*/
private const PHPDOC_TYPE_MAPPER_CLASSES = [IdentifierTypeMapper::class, IntersectionTypeMapper::class, NullableTypeMapper::class, UnionTypeMapper::class];
/**
* @var array<class-string<TypeMapperInterface>>
*/
private const TYPE_MAPPER_CLASSES = [AccessoryLiteralStringTypeMapper::class, AccessoryNonEmptyStringTypeMapper::class, AccessoryNonFalsyStringTypeMapper::class, AccessoryNumericStringTypeMapper::class, ArrayTypeMapper::class, BooleanTypeMapper::class, CallableTypeMapper::class, ClassStringTypeMapper::class, ClosureTypeMapper::class, ConditionalTypeForParameterMapper::class, ConditionalTypeMapper::class, FloatTypeMapper::class, GenericClassStringTypeMapper::class, HasMethodTypeMapper::class, HasOffsetTypeMapper::class, HasOffsetValueTypeTypeMapper::class, HasPropertyTypeMapper::class, IntegerTypeMapper::class, \Rector\PHPStanStaticTypeMapper\TypeMapper\IntersectionTypeMapper::class, IterableTypeMapper::class, MixedTypeMapper::class, NeverTypeMapper::class, NonEmptyArrayTypeMapper::class, NullTypeMapper::class, ObjectTypeMapper::class, ObjectWithoutClassTypeMapper::class, OversizedArrayTypeMapper::class, ParentStaticTypeMapper::class, ResourceTypeMapper::class, SelfObjectTypeMapper::class, \Rector\PHPStanStaticTypeMapper\TypeMapper\StaticTypeMapper::class, StrictMixedTypeMapper::class, StringTypeMapper::class, ThisTypeMapper::class, TypeWithClassNameTypeMapper::class, \Rector\PHPStanStaticTypeMapper\TypeMapper\UnionTypeMapper::class, VoidTypeMapper::class];
/**
* @api used as next container factory
*/
Expand Down Expand Up @@ -121,13 +174,26 @@ public function create() : Container
// node name resolvers
$container->when(NodeNameResolver::class)->needs('$nodeNameResolvers')->giveTagged(NodeNameResolverInterface::class);
$this->registerTagged($container, self::NODE_NAME_RESOLVER_CLASSES, NodeNameResolverInterface::class);
$this->registerTagged($container, self::PHPDOC_TYPE_MAPPER_CLASSES, PhpDocTypeMapperInterface::class);
$this->registerTagged($container, self::TYPE_MAPPER_CLASSES, TypeMapperInterface::class);
$container->when(AnnotationToAttributeMapper::class)->needs('$annotationToAttributeMappers')->giveTagged(AnnotationToAttributeMapperInterface::class);
$this->registerTagged($container, self::ANNOTATION_TO_ATTRIBUTE_MAPPER_CLASSES, AnnotationToAttributeMapperInterface::class);
// #[Required]-like setter
$container->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 {
$annotationToAttributeMapper = $container->make(AnnotationToAttributeMapper::class);
$arrayItemNodeAnnotationToAttributeMapper->autowire($annotationToAttributeMapper);
});
$container->afterResolving(ShortNameResolver::class, static function (ShortNameResolver $shortNameResolver, Container $container) : void {
$phpDocInfoFactory = $container->make(PhpDocInfoFactory::class);
$shortNameResolver->autowire($phpDocInfoFactory);
});
$container->afterResolving(NameScopeFactory::class, static function (NameScopeFactory $nameScopeFactory, Container $container) : void {
$nameScopeFactory->autowire($container->make(PhpDocInfoFactory::class), $container->make(StaticTypeMapper::class), $container->make(ReflectionResolver::class), $container->make(ClassLikeAstResolver::class));
});
$container->singleton(Parser::class, static function (Container $container) {
$phpstanServiceFactory = $container->make(PHPStanServicesFactory::class);
return $phpstanServiceFactory->createPHPStanParser();
Expand All @@ -147,6 +213,7 @@ public function create() : Container
private function registerTagged(Container $container, array $classes, string $tagInterface) : void
{
foreach ($classes as $class) {
Assert::isAOf($class, $tagInterface);
$container->singleton($class);
$container->tag($class, $tagInterface);
}
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 ComposerAutoloaderInitbc2bb71349665d13f9dfd88b40dccdda::getLoader();
return ComposerAutoloaderInitd080db0a1bafff113ca284ca66fce5f9::getLoader();
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 ComposerAutoloaderInitbc2bb71349665d13f9dfd88b40dccdda
class ComposerAutoloaderInitd080db0a1bafff113ca284ca66fce5f9
{
private static $loader;

Expand All @@ -22,17 +22,17 @@ public static function getLoader()
return self::$loader;
}

spl_autoload_register(array('ComposerAutoloaderInitbc2bb71349665d13f9dfd88b40dccdda', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitd080db0a1bafff113ca284ca66fce5f9', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInitbc2bb71349665d13f9dfd88b40dccdda', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitd080db0a1bafff113ca284ca66fce5f9', 'loadClassLoader'));

require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9::getInitializer($loader));

$loader->setClassMapAuthoritative(true);
$loader->register(true);

$filesToLoad = \Composer\Autoload\ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
Expand Down
8 changes: 4 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 ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda
class ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
Expand Down Expand Up @@ -3010,9 +3010,9 @@ class ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitbc2bb71349665d13f9dfd88b40dccdda::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitd080db0a1bafff113ca284ca66fce5f9::$classMap;

}, null, ClassLoader::class);
}
Expand Down

0 comments on commit b4217dc

Please sign in to comment.