@@ -48,6 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
48
48
$ this ->processFactory ->setOutput ($ output );
49
49
50
50
$ this ->fixComposerJson ($ this ->buildDir );
51
+ $ this ->renamePhpStormStubs ();
51
52
$ this ->processFactory ->create (['composer ' , 'update ' , '--no-dev ' , '--classmap-authoritative ' ], $ this ->buildDir );
52
53
53
54
$ this ->processFactory ->create (['php ' , 'box.phar ' , 'compile ' , '--no-parallel ' ], $ this ->dataDir );
@@ -76,4 +77,41 @@ private function fixComposerJson(string $buildDir): void
76
77
$ this ->filesystem ->write ($ buildDir . '/composer.json ' , $ encodedJson );
77
78
}
78
79
80
+ private function renamePhpStormStubs (): void
81
+ {
82
+ $ directory = $ this ->buildDir . '/vendor/jetbrains/phpstorm-stubs ' ;
83
+ if (!is_dir ($ directory )) {
84
+ return ;
85
+ }
86
+
87
+ $ stubFinder = \Symfony \Component \Finder \Finder::create ();
88
+ $ stubsMapPath = $ directory . '/PhpStormStubsMap.php ' ;
89
+ foreach ($ stubFinder ->files ()->name ('*.php ' )->in ($ directory ) as $ stubFile ) {
90
+ $ path = $ stubFile ->getPathname ();
91
+ if ($ path === $ stubsMapPath ) {
92
+ continue ;
93
+ }
94
+
95
+ $ renameSuccess = rename (
96
+ $ path ,
97
+ dirname ($ path ) . '/ ' . $ stubFile ->getBasename ('.php ' ) . '.stub '
98
+ );
99
+ if ($ renameSuccess === false ) {
100
+ throw new \PHPStan \ShouldNotHappenException (sprintf ('Could not rename %s ' , $ path ));
101
+ }
102
+ }
103
+
104
+ $ stubsMapContents = file_get_contents ($ stubsMapPath );
105
+ if ($ stubsMapContents === false ) {
106
+ throw new \PHPStan \ShouldNotHappenException (sprintf ('Could not read %s ' , $ stubsMapPath ));
107
+ }
108
+
109
+ $ stubsMapContents = str_replace ('.php \', ' , '.stub \', ' , $ stubsMapContents );
110
+
111
+ $ putSuccess = file_put_contents ($ directory . '/PhpStormStubsMap.php ' , $ stubsMapContents );
112
+ if ($ putSuccess === false ) {
113
+ throw new \PHPStan \ShouldNotHappenException (sprintf ('Could not write %s ' , $ stubsMapPath ));
114
+ }
115
+ }
116
+
79
117
}
0 commit comments