Skip to content

Commit 1cd97b4

Browse files
committed
More cleanup
I realized that "files" from composer.json are already loaded so AutoloadSourceLocator will work even for functions
1 parent 73aede3 commit 1cd97b4

6 files changed

Lines changed: 2 additions & 192 deletions

File tree

compiler/build/scoper.inc.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,16 +148,6 @@ function (string $filePath, string $prefix, string $content): string {
148148

149149
return \Nette\Neon\Neon::encode($updatedNeon, \Nette\Neon\Neon::BLOCK);
150150
},
151-
function (string $filePath, string $prefix, string $content): string {
152-
if (!in_array($filePath, [
153-
'src/Testing/TestCaseSourceLocatorFactory.php',
154-
'src/Testing/TestCase.php',
155-
], true)) {
156-
return $content;
157-
}
158-
159-
return str_replace(sprintf('%s\\Composer\\Autoload\\ClassLoader', $prefix), 'Composer\\Autoload\\ClassLoader', $content);
160-
},
161151
function (string $filePath, string $prefix, string $content): string {
162152
if ($filePath !== 'vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php') {
163153
return $content;

conf/config.neon

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,9 +490,6 @@ services:
490490
-
491491
class: PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator
492492

493-
-
494-
class: PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker
495-
496493
-
497494
implement: PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorFactory
498495

@@ -1152,7 +1149,6 @@ services:
11521149
scanFiles: %scanFiles%
11531150
scanDirectories: %scanDirectories%
11541151
analysedPaths: %analysedPaths%
1155-
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
11561152
analysedPathsFromConfig: %analysedPathsFromConfig%
11571153
singleReflectionFile: %singleReflectionFile%
11581154

src/Reflection/BetterReflection/BetterReflectionSourceLocatorFactory.php

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use PHPStan\DependencyInjection\Container;
66
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
7-
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
87
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorRepository;
98
use PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedSingleFileSourceLocatorRepository;
109
use PHPStan\Reflection\BetterReflection\SourceLocator\SkipClassAliasSourceLocator;
@@ -37,9 +36,6 @@ class BetterReflectionSourceLocatorFactory
3736
/** @var \PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocatorRepository */
3837
private $optimizedDirectorySourceLocatorRepository;
3938

40-
/** @var ComposerJsonAndInstalledJsonSourceLocatorMaker */
41-
private $composerJsonAndInstalledJsonSourceLocatorMaker;
42-
4339
/** @var AutoloadSourceLocator */
4440
private $autoloadSourceLocator;
4541

@@ -61,9 +57,6 @@ class BetterReflectionSourceLocatorFactory
6157
/** @var string[] */
6258
private $analysedPaths;
6359

64-
/** @var string[] */
65-
private $composerAutoloaderProjectPaths;
66-
6760
/** @var string[] */
6861
private $analysedPathsFromConfig;
6962

@@ -76,7 +69,6 @@ class BetterReflectionSourceLocatorFactory
7669
* @param string[] $scanFiles
7770
* @param string[] $scanDirectories
7871
* @param string[] $analysedPaths
79-
* @param string[] $composerAutoloaderProjectPaths
8072
* @param string[] $analysedPathsFromConfig
8173
* @param string|null $singleReflectionFile
8274
*/
@@ -86,15 +78,13 @@ public function __construct(
8678
ReflectionSourceStubber $reflectionSourceStubber,
8779
OptimizedSingleFileSourceLocatorRepository $optimizedSingleFileSourceLocatorRepository,
8880
OptimizedDirectorySourceLocatorRepository $optimizedDirectorySourceLocatorRepository,
89-
ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker,
9081
AutoloadSourceLocator $autoloadSourceLocator,
9182
Container $container,
9283
array $autoloadDirectories,
9384
array $autoloadFiles,
9485
array $scanFiles,
9586
array $scanDirectories,
9687
array $analysedPaths,
97-
array $composerAutoloaderProjectPaths,
9888
array $analysedPathsFromConfig,
9989
?string $singleReflectionFile
10090
)
@@ -104,15 +94,13 @@ public function __construct(
10494
$this->reflectionSourceStubber = $reflectionSourceStubber;
10595
$this->optimizedSingleFileSourceLocatorRepository = $optimizedSingleFileSourceLocatorRepository;
10696
$this->optimizedDirectorySourceLocatorRepository = $optimizedDirectorySourceLocatorRepository;
107-
$this->composerJsonAndInstalledJsonSourceLocatorMaker = $composerJsonAndInstalledJsonSourceLocatorMaker;
10897
$this->autoloadSourceLocator = $autoloadSourceLocator;
10998
$this->container = $container;
11099
$this->autoloadDirectories = $autoloadDirectories;
111100
$this->autoloadFiles = $autoloadFiles;
112101
$this->scanFiles = $scanFiles;
113102
$this->scanDirectories = $scanDirectories;
114103
$this->analysedPaths = $analysedPaths;
115-
$this->composerAutoloaderProjectPaths = $composerAutoloaderProjectPaths;
116104
$this->analysedPathsFromConfig = $analysedPathsFromConfig;
117105
$this->singleReflectionFile = $singleReflectionFile;
118106
}
@@ -156,13 +144,6 @@ public function create(): SourceLocator
156144
});
157145
$locators[] = new SkipClassAliasSourceLocator(new PhpInternalSourceLocator($astLocator, $this->phpstormStubsSourceStubber));
158146
$locators[] = $this->autoloadSourceLocator;
159-
foreach ($this->composerAutoloaderProjectPaths as $composerAutoloaderProjectPath) {
160-
$locator = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerAutoloaderProjectPath);
161-
if ($locator === null) {
162-
continue;
163-
}
164-
$locators[] = $locator;
165-
}
166147
$locators[] = new PhpInternalSourceLocator($astLocator, $this->reflectionSourceStubber);
167148
$locators[] = new EvaledCodeSourceLocator($astLocator, $this->reflectionSourceStubber);
168149

src/Reflection/BetterReflection/SourceLocator/ComposerJsonAndInstalledJsonSourceLocatorMaker.php

Lines changed: 0 additions & 110 deletions
This file was deleted.

src/Testing/TestCase.php

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Testing;
44

5-
use Composer\Autoload\ClassLoader;
65
use PhpParser\PrettyPrinter\Standard;
76
use PHPStan\Analyser\DirectScopeFactory;
87
use PHPStan\Analyser\MutatingScope;
@@ -37,7 +36,6 @@
3736
use PHPStan\Reflection\BetterReflection\Reflector\MemoizingConstantReflector;
3837
use PHPStan\Reflection\BetterReflection\Reflector\MemoizingFunctionReflector;
3938
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
40-
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
4139
use PHPStan\Reflection\BetterReflection\SourceLocator\FileNodesFetcher;
4240
use PHPStan\Reflection\ClassReflection;
4341
use PHPStan\Reflection\FunctionReflectionFactory;
@@ -409,31 +407,9 @@ public static function getReflectors(): array
409407
return self::$reflectors;
410408
}
411409

412-
if (!class_exists(ClassLoader::class)) {
413-
self::fail('Composer ClassLoader is unknown');
414-
}
415-
416-
$classLoaderReflection = new \ReflectionClass(ClassLoader::class);
417-
if ($classLoaderReflection->getFileName() === false) {
418-
self::fail('Unknown ClassLoader filename');
419-
}
420-
421-
$composerProjectPath = dirname($classLoaderReflection->getFileName(), 3);
422-
if (!is_file($composerProjectPath . '/composer.json')) {
423-
self::fail(sprintf('composer.json not found in directory %s', $composerProjectPath));
424-
}
425-
426-
$composerJsonAndInstalledJsonSourceLocatorMaker = self::getContainer()->getByType(ComposerJsonAndInstalledJsonSourceLocatorMaker::class);
427-
$composerSourceLocator = $composerJsonAndInstalledJsonSourceLocatorMaker->create($composerProjectPath);
428-
if ($composerSourceLocator === null) {
429-
self::fail('Could not create composer source locator');
430-
}
431-
432410
// these need to be synced with TestCase-staticReflection.neon file and TestCaseSourceLocatorFactory
433411

434-
$locators = [
435-
$composerSourceLocator,
436-
];
412+
$locators = [];
437413

438414
$phpParser = new PhpParserDecorator(self::getContainer()->getByType(CachedParser::class));
439415

src/Testing/TestCaseSourceLocatorFactory.php

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
namespace PHPStan\Testing;
44

5-
use Composer\Autoload\ClassLoader;
65
use PHPStan\DependencyInjection\Container;
76
use PHPStan\Reflection\BetterReflection\SourceLocator\AutoloadSourceLocator;
8-
use PHPStan\Reflection\BetterReflection\SourceLocator\ComposerJsonAndInstalledJsonSourceLocatorMaker;
97
use Roave\BetterReflection\Reflector\FunctionReflector;
108
use Roave\BetterReflection\SourceLocator\Ast\Locator;
119
use Roave\BetterReflection\SourceLocator\SourceStubber\PhpStormStubsSourceStubber;
@@ -21,8 +19,6 @@ class TestCaseSourceLocatorFactory
2119

2220
private Container $container;
2321

24-
private ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker;
25-
2622
private AutoloadSourceLocator $autoloadSourceLocator;
2723

2824
private \PhpParser\Parser $phpParser;
@@ -33,15 +29,13 @@ class TestCaseSourceLocatorFactory
3329

3430
public function __construct(
3531
Container $container,
36-
ComposerJsonAndInstalledJsonSourceLocatorMaker $composerJsonAndInstalledJsonSourceLocatorMaker,
3732
AutoloadSourceLocator $autoloadSourceLocator,
3833
\PhpParser\Parser $phpParser,
3934
PhpStormStubsSourceStubber $phpstormStubsSourceStubber,
4035
ReflectionSourceStubber $reflectionSourceStubber
4136
)
4237
{
4338
$this->container = $container;
44-
$this->composerJsonAndInstalledJsonSourceLocatorMaker = $composerJsonAndInstalledJsonSourceLocatorMaker;
4539
$this->autoloadSourceLocator = $autoloadSourceLocator;
4640
$this->phpParser = $phpParser;
4741
$this->phpstormStubsSourceStubber = $phpstormStubsSourceStubber;
@@ -50,24 +44,7 @@ public function __construct(
5044

5145
public function create(): SourceLocator
5246
{
53-
$classLoaderReflection = new \ReflectionClass(ClassLoader::class);
54-
if ($classLoaderReflection->getFileName() === false) {
55-
throw new \PHPStan\ShouldNotHappenException('Unknown ClassLoader filename');
56-
}
57-
58-
$composerProjectPath = dirname($classLoaderReflection->getFileName(), 3);
59-
if (!is_file($composerProjectPath . '/composer.json')) {
60-
throw new \PHPStan\ShouldNotHappenException(sprintf('composer.json not found in directory %s', $composerProjectPath));
61-
}
62-
63-
$composerSourceLocator = $this->composerJsonAndInstalledJsonSourceLocatorMaker->create($composerProjectPath);
64-
if ($composerSourceLocator === null) {
65-
throw new \PHPStan\ShouldNotHappenException('Could not create composer source locator');
66-
}
67-
68-
$locators = [
69-
$composerSourceLocator,
70-
];
47+
$locators = [];
7148
$astLocator = new Locator($this->phpParser, function (): FunctionReflector {
7249
return $this->container->getService('testCaseFunctionReflector');
7350
});

0 commit comments

Comments
 (0)