Skip to content

Commit d6dc063

Browse files
committed
Updated Rector to commit 2e36fffb357edc40a64d69266e8747fcf9fdd679
rectorphp/rector-src@2e36fff [Bc Break] [Alternative] Drop children class detection (#5995)
1 parent d5a6bce commit d6dc063

File tree

7 files changed

+8
-213
lines changed

7 files changed

+8
-213
lines changed

src/Application/ApplicationFileProcessor.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
namespace Rector\Application;
55

66
use RectorPrefix202406\Nette\Utils\FileSystem as UtilsFileSystem;
7-
use Rector\Caching\Cache;
87
use Rector\Caching\Detector\ChangedFilesDetector;
98
use Rector\Configuration\Option;
109
use Rector\Configuration\Parameter\SimpleParameterProvider;
1110
use Rector\Configuration\VendorMissAnalyseGuard;
12-
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
1311
use Rector\Parallel\Application\ParallelFileProcessor;
1412
use Rector\Provider\CurrentFileProvider;
1513
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
@@ -79,16 +77,6 @@ final class ApplicationFileProcessor
7977
* @var \Rector\Configuration\VendorMissAnalyseGuard
8078
*/
8179
private $vendorMissAnalyseGuard;
82-
/**
83-
* @readonly
84-
* @var \Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider
85-
*/
86-
private $dynamicSourceLocatorProvider;
87-
/**
88-
* @readonly
89-
* @var \Rector\Caching\Cache
90-
*/
91-
private $cache;
9280
/**
9381
* @var string
9482
*/
@@ -97,7 +85,7 @@ final class ApplicationFileProcessor
9785
* @var SystemError[]
9886
*/
9987
private $systemErrors = [];
100-
public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, \Rector\Application\FileProcessor $fileProcessor, ArrayParametersMerger $arrayParametersMerger, VendorMissAnalyseGuard $vendorMissAnalyseGuard, DynamicSourceLocatorProvider $dynamicSourceLocatorProvider, Cache $cache)
88+
public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory, ParallelFileProcessor $parallelFileProcessor, ScheduleFactory $scheduleFactory, CpuCoreCountProvider $cpuCoreCountProvider, ChangedFilesDetector $changedFilesDetector, CurrentFileProvider $currentFileProvider, \Rector\Application\FileProcessor $fileProcessor, ArrayParametersMerger $arrayParametersMerger, VendorMissAnalyseGuard $vendorMissAnalyseGuard)
10189
{
10290
$this->symfonyStyle = $symfonyStyle;
10391
$this->fileFactory = $fileFactory;
@@ -109,8 +97,6 @@ public function __construct(SymfonyStyle $symfonyStyle, FileFactory $fileFactory
10997
$this->fileProcessor = $fileProcessor;
11098
$this->arrayParametersMerger = $arrayParametersMerger;
11199
$this->vendorMissAnalyseGuard = $vendorMissAnalyseGuard;
112-
$this->dynamicSourceLocatorProvider = $dynamicSourceLocatorProvider;
113-
$this->cache = $cache;
114100
}
115101
public function run(Configuration $configuration, InputInterface $input) : ProcessResult
116102
{
@@ -121,9 +107,6 @@ public function run(Configuration $configuration, InputInterface $input) : Proce
121107
if ($filePaths === []) {
122108
return new ProcessResult([], []);
123109
}
124-
// ensure clear classnames collection caches on repetitive call
125-
$key = $this->dynamicSourceLocatorProvider->getCacheClassNameKey();
126-
$this->cache->clean($key);
127110
$this->configureCustomErrorHandler();
128111
/**
129112
* Mimic @see https://github.com/phpstan/phpstan-src/blob/ab154e1da54d42fec751e17a1199b3e07591e85e/src/Command/AnalyseApplication.php#L188C23-L244
@@ -147,8 +130,6 @@ public function run(Configuration $configuration, InputInterface $input) : Proce
147130
} else {
148131
$preFileCallback = null;
149132
}
150-
// trigger cache class names collection
151-
$this->dynamicSourceLocatorProvider->provide();
152133
if ($configuration->isParallel()) {
153134
$processResult = $this->runParallel($filePaths, $input, $postFileCallback);
154135
} else {

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '07dc58043d4a4634e6376094af98a3233719a2da';
22+
public const PACKAGE_VERSION = '2e36fffb357edc40a64d69266e8747fcf9fdd679';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-06-21 02:28:40';
27+
public const RELEASE_DATE = '2024-06-21 09:42:39';
2828
/**
2929
* @var int
3030
*/

src/Caching/Enum/CacheKey.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,4 @@ final class CacheKey
1616
* @var string
1717
*/
1818
public const FILE_HASH_KEY = 'file_hash';
19-
/**
20-
* @var string
21-
*/
22-
public const CLASSNAMES_HASH_KEY = 'classnames_hash';
2319
}

src/DependencyInjection/LazyContainerFactory.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@
179179
use Rector\StaticTypeMapper\PhpParser\StringNodeMapper;
180180
use Rector\StaticTypeMapper\PhpParser\UnionTypeNodeMapper;
181181
use Rector\StaticTypeMapper\StaticTypeMapper;
182-
use Rector\Util\FileHasher;
183182
use Rector\Utils\Command\MissingInSetCommand;
184183
use Rector\Utils\Command\OutsideAnySetCommand;
185184
use RectorPrefix202406\Symfony\Component\Console\Application;
@@ -290,9 +289,6 @@ public function create() : RectorConfig
290289
$phpStanServicesFactory = $container->make(PHPStanServicesFactory::class);
291290
return $phpStanServicesFactory->createDynamicSourceLocatorProvider();
292291
});
293-
$rectorConfig->afterResolving(DynamicSourceLocatorProvider::class, static function (DynamicSourceLocatorProvider $dynamicSourceLocatorProvider, Container $container) : void {
294-
$dynamicSourceLocatorProvider->autowire($container->make(Cache::class), $container->make(FileHasher::class));
295-
});
296292
// resetables
297293
$rectorConfig->tag(DynamicSourceLocatorProvider::class, ResetableInterface::class);
298294
$rectorConfig->tag(RenamedClassesDataCollector::class, ResetableInterface::class);

src/FamilyTree/Reflection/FamilyRelationsAnalyzer.php

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@
66
use PhpParser\Node\Name;
77
use PhpParser\Node\Stmt\Class_;
88
use PhpParser\Node\Stmt\Interface_;
9-
use PHPStan\Broker\ClassNotFoundException;
109
use PHPStan\Reflection\ClassReflection;
1110
use PHPStan\Reflection\ReflectionProvider;
12-
use PHPStan\ShouldNotHappenException;
13-
use Rector\Caching\Cache;
14-
use Rector\Caching\Enum\CacheKey;
1511
use Rector\NodeNameResolver\NodeNameResolver;
16-
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
17-
use Rector\Util\Reflection\PrivatesAccessor;
1812
final class FamilyRelationsAnalyzer
1913
{
2014
/**
@@ -27,53 +21,10 @@ final class FamilyRelationsAnalyzer
2721
* @var \Rector\NodeNameResolver\NodeNameResolver
2822
*/
2923
private $nodeNameResolver;
30-
/**
31-
* @readonly
32-
* @var \Rector\Util\Reflection\PrivatesAccessor
33-
*/
34-
private $privatesAccessor;
35-
/**
36-
* @readonly
37-
* @var \Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider
38-
*/
39-
private $dynamicSourceLocatorProvider;
40-
/**
41-
* @readonly
42-
* @var \Rector\Caching\Cache
43-
*/
44-
private $cache;
45-
/**
46-
* @var bool
47-
*/
48-
private $hasClassNamesCachedOrLoadOneLocator = \false;
49-
public function __construct(ReflectionProvider $reflectionProvider, NodeNameResolver $nodeNameResolver, PrivatesAccessor $privatesAccessor, DynamicSourceLocatorProvider $dynamicSourceLocatorProvider, Cache $cache, bool $hasClassNamesCachedOrLoadOneLocator = \false)
24+
public function __construct(ReflectionProvider $reflectionProvider, NodeNameResolver $nodeNameResolver)
5025
{
5126
$this->reflectionProvider = $reflectionProvider;
5227
$this->nodeNameResolver = $nodeNameResolver;
53-
$this->privatesAccessor = $privatesAccessor;
54-
$this->dynamicSourceLocatorProvider = $dynamicSourceLocatorProvider;
55-
$this->cache = $cache;
56-
$this->hasClassNamesCachedOrLoadOneLocator = $hasClassNamesCachedOrLoadOneLocator;
57-
}
58-
/**
59-
* @return ClassReflection[]
60-
*/
61-
public function getChildrenOfClassReflection(ClassReflection $desiredClassReflection) : array
62-
{
63-
if ($desiredClassReflection->isFinalByKeyword()) {
64-
return [];
65-
}
66-
$this->loadClasses();
67-
/** @var ClassReflection[] $classReflections */
68-
$classReflections = $this->privatesAccessor->getPrivateProperty($this->reflectionProvider, 'classes');
69-
$childrenClassReflections = [];
70-
foreach ($classReflections as $classReflection) {
71-
if (!$classReflection->isSubclassOf($desiredClassReflection->getName())) {
72-
continue;
73-
}
74-
$childrenClassReflections[] = $classReflection;
75-
}
76-
return $childrenClassReflections;
7728
}
7829
/**
7930
* @api
@@ -113,21 +64,4 @@ public function getClassLikeAncestorNames($classOrName) : array
11364
/** @var string[] $ancestorNames */
11465
return $ancestorNames;
11566
}
116-
private function loadClasses() : void
117-
{
118-
if ($this->hasClassNamesCachedOrLoadOneLocator) {
119-
return;
120-
}
121-
$key = $this->dynamicSourceLocatorProvider->getCacheClassNameKey();
122-
$classNamesCache = $this->cache->load($key, CacheKey::CLASSNAMES_HASH_KEY);
123-
if (\is_array($classNamesCache)) {
124-
foreach ($classNamesCache as $classNameCache) {
125-
try {
126-
$this->reflectionProvider->getClass($classNameCache);
127-
} catch (ClassNotFoundException|ShouldNotHappenException $exception) {
128-
}
129-
}
130-
}
131-
$this->hasClassNamesCachedOrLoadOneLocator = \true;
132-
}
13367
}

src/NodeTypeResolver/Reflection/BetterReflection/SourceLocatorProvider/DynamicSourceLocatorProvider.php

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,13 @@
33
declare (strict_types=1);
44
namespace Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider;
55

6-
use PHPStan\BetterReflection\Reflector\DefaultReflector;
76
use PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator;
87
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator;
9-
use PHPStan\File\CouldNotReadFileException;
108
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
11-
use PHPStan\Reflection\BetterReflection\SourceLocator\NewOptimizedDirectorySourceLocator;
129
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory;
1310
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocator;
14-
use Rector\Caching\Cache;
15-
use Rector\Caching\Enum\CacheKey;
1611
use Rector\Contract\DependencyInjection\ResetableInterface;
1712
use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
18-
use Rector\Util\FileHasher;
1913
/**
2014
* @api phpstan external
2115
*/
@@ -43,40 +37,15 @@ final class DynamicSourceLocatorProvider implements ResetableInterface
4337
* @var \PHPStan\BetterReflection\SourceLocator\Type\AggregateSourceLocator|null
4438
*/
4539
private $aggregateSourceLocator;
46-
/**
47-
* @var \Rector\Caching\Cache
48-
*/
49-
private $cache;
50-
/**
51-
* @var \Rector\Util\FileHasher
52-
*/
53-
private $fileHasher;
5440
public function __construct(FileNodesFetcher $fileNodesFetcher, OptimizedDirectorySourceLocatorFactory $optimizedDirectorySourceLocatorFactory)
5541
{
5642
$this->fileNodesFetcher = $fileNodesFetcher;
5743
$this->optimizedDirectorySourceLocatorFactory = $optimizedDirectorySourceLocatorFactory;
5844
}
59-
public function autowire(Cache $cache, FileHasher $fileHasher) : void
60-
{
61-
$this->cache = $cache;
62-
$this->fileHasher = $fileHasher;
63-
}
6445
public function setFilePath(string $filePath) : void
6546
{
6647
$this->filePaths = [$filePath];
6748
}
68-
public function getCacheClassNameKey() : string
69-
{
70-
$paths = [];
71-
foreach ($this->filePaths as $filePath) {
72-
$paths[] = (string) \realpath($filePath);
73-
}
74-
foreach ($this->directories as $directory) {
75-
$paths[] = (string) \realpath($directory);
76-
}
77-
$paths = \array_filter($paths);
78-
return CacheKey::CLASSNAMES_HASH_KEY . '_' . $this->fileHasher->hash((string) \json_encode($paths));
79-
}
8049
/**
8150
* @param string[] $files
8251
*/
@@ -105,9 +74,7 @@ public function provide() : SourceLocator
10574
foreach ($this->directories as $directory) {
10675
$sourceLocators[] = $this->optimizedDirectorySourceLocatorFactory->createByDirectory($directory);
10776
}
108-
$aggregateSourceLocator = $this->aggregateSourceLocator = new AggregateSourceLocator($sourceLocators);
109-
$this->collectClasses($aggregateSourceLocator, $sourceLocators);
110-
return $aggregateSourceLocator;
77+
return $this->aggregateSourceLocator = new AggregateSourceLocator($sourceLocators);
11178
}
11279
public function isPathsEmpty() : bool
11380
{
@@ -122,33 +89,4 @@ public function reset() : void
12289
$this->directories = [];
12390
$this->aggregateSourceLocator = null;
12491
}
125-
/**
126-
* @param OptimizedSingleFileSourceLocator[]|NewOptimizedDirectorySourceLocator[] $sourceLocators
127-
*/
128-
private function collectClasses(AggregateSourceLocator $aggregateSourceLocator, array $sourceLocators) : void
129-
{
130-
if ($sourceLocators === []) {
131-
return;
132-
}
133-
// no need to collect classes on single file, will auto collected
134-
if (\count($sourceLocators) === 1 && $sourceLocators[0] instanceof OptimizedSingleFileSourceLocator) {
135-
return;
136-
}
137-
$key = $this->getCacheClassNameKey();
138-
$classNamesCache = $this->cache->load($key, CacheKey::CLASSNAMES_HASH_KEY);
139-
if (\is_array($classNamesCache)) {
140-
return;
141-
}
142-
$reflector = new DefaultReflector($aggregateSourceLocator);
143-
$classNames = [];
144-
// trigger collect "classes" on get class on locate identifier
145-
try {
146-
$reflections = $reflector->reflectAllClasses();
147-
foreach ($reflections as $reflection) {
148-
$classNames[] = $reflection->getName();
149-
}
150-
} catch (CouldNotReadFileException $exception) {
151-
}
152-
$this->cache->save($key, CacheKey::CLASSNAMES_HASH_KEY, $classNames);
153-
}
15492
}

0 commit comments

Comments
 (0)