16
16
use PHPStan \Reflection \BetterReflection \SourceLocator \AutoloadSourceLocator ;
17
17
use PHPStan \Reflection \BetterReflection \SourceLocator \ComposerJsonAndInstalledJsonSourceLocatorMaker ;
18
18
use PHPStan \Reflection \BetterReflection \SourceLocator \FileNodesFetcher ;
19
+ use PHPStan \Reflection \BetterReflection \SourceLocator \OptimizedSingleFileSourceLocatorRepository ;
19
20
use PHPStan \Reflection \BetterReflection \SourceLocator \PhpVersionBlacklistSourceLocator ;
20
21
use ReflectionClass ;
21
22
use function dirname ;
22
23
use function is_file ;
23
24
use function serialize ;
24
25
use function sha1 ;
26
+ use const PHP_VERSION_ID ;
25
27
26
28
final class TestCaseSourceLocatorFactory
27
29
{
@@ -35,6 +37,7 @@ final class TestCaseSourceLocatorFactory
35
37
*/
36
38
public function __construct (
37
39
private ComposerJsonAndInstalledJsonSourceLocatorMaker $ composerJsonAndInstalledJsonSourceLocatorMaker ,
40
+ private OptimizedSingleFileSourceLocatorRepository $ optimizedSingleFileSourceLocatorRepository ,
38
41
private Parser $ phpParser ,
39
42
private Parser $ php8Parser ,
40
43
private FileNodesFetcher $ fileNodesFetcher ,
@@ -57,7 +60,13 @@ public function create(): SourceLocator
57
60
$ this ->excludePaths ,
58
61
]));
59
62
if ($ classLoaderReflection ->hasProperty ('vendorDir ' ) && ! isset (self ::$ composerSourceLocatorsCache [$ cacheKey ])) {
60
- $ composerLocators = [];
63
+ $ composerLocators = [
64
+ $ this ->optimizedSingleFileSourceLocatorRepository ->getOrCreate (
65
+ PHP_VERSION_ID < 80500
66
+ ? __DIR__ . '/../../stubs/runtime/Attribute84.php '
67
+ : __DIR__ . '/../../stubs/runtime/Attribute85.php ' ,
68
+ ),
69
+ ];
61
70
$ vendorDirProperty = $ classLoaderReflection ->getProperty ('vendorDir ' );
62
71
$ vendorDirProperty ->setAccessible (true );
63
72
foreach ($ classLoaders as $ classLoader ) {
0 commit comments