22
33namespace PHPStan \Compiler \Console ;
44
5+ use Exception ;
56use PHPStan \Compiler \Filesystem \Filesystem ;
67use PHPStan \Compiler \Process \ProcessFactory ;
8+ use PHPStan \ShouldNotHappenException ;
79use Symfony \Component \Console \Command \Command ;
810use Symfony \Component \Console \Input \InputInterface ;
911use Symfony \Component \Console \Output \OutputInterface ;
12+ use Symfony \Component \Finder \Finder ;
13+ use function basename ;
14+ use function dirname ;
1015use function escapeshellarg ;
16+ use function exec ;
17+ use function file_get_contents ;
18+ use function file_put_contents ;
19+ use function implode ;
20+ use function is_dir ;
21+ use function json_decode ;
22+ use function json_encode ;
23+ use function realpath ;
24+ use function rename ;
25+ use function sprintf ;
26+ use function str_replace ;
27+ use function strlen ;
28+ use function substr ;
29+ use function unlink ;
30+ use function var_export ;
31+ use const JSON_PRETTY_PRINT ;
32+ use const JSON_UNESCAPED_SLASHES ;
1133
1234final class CompileCommand extends Command
1335{
@@ -74,7 +96,7 @@ private function fixComposerJson(string $buildDir): void
7496
7597 $ encodedJson = json_encode ($ json , JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT );
7698 if ($ encodedJson === false ) {
77- throw new \ Exception ('json_encode() was not successful. ' );
99+ throw new Exception ('json_encode() was not successful. ' );
78100 }
79101
80102 $ this ->filesystem ->write ($ buildDir . '/composer.json ' , $ encodedJson );
@@ -87,10 +109,10 @@ private function renamePhpStormStubs(): void
87109 return ;
88110 }
89111
90- $ stubFinder = \ Symfony \ Component \ Finder \ Finder::create ();
112+ $ stubFinder = Finder::create ();
91113 $ stubsMapPath = realpath ($ directory . '/PhpStormStubsMap.php ' );
92114 if ($ stubsMapPath === false ) {
93- throw new \ Exception ('realpath() failed ' );
115+ throw new Exception ('realpath() failed ' );
94116 }
95117 foreach ($ stubFinder ->files ()->name ('*.php ' )->in ($ directory ) as $ stubFile ) {
96118 $ path = $ stubFile ->getPathname ();
@@ -103,20 +125,20 @@ private function renamePhpStormStubs(): void
103125 dirname ($ path ) . '/ ' . $ stubFile ->getBasename ('.php ' ) . '.stub '
104126 );
105127 if ($ renameSuccess === false ) {
106- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not rename %s ' , $ path ));
128+ throw new ShouldNotHappenException (sprintf ('Could not rename %s ' , $ path ));
107129 }
108130 }
109131
110132 $ stubsMapContents = file_get_contents ($ stubsMapPath );
111133 if ($ stubsMapContents === false ) {
112- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not read %s ' , $ stubsMapPath ));
134+ throw new ShouldNotHappenException (sprintf ('Could not read %s ' , $ stubsMapPath ));
113135 }
114136
115137 $ stubsMapContents = str_replace ('.php \', ' , '.stub \', ' , $ stubsMapContents );
116138
117139 $ putSuccess = file_put_contents ($ stubsMapPath , $ stubsMapContents );
118140 if ($ putSuccess === false ) {
119- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not write %s ' , $ stubsMapPath ));
141+ throw new ShouldNotHappenException (sprintf ('Could not write %s ' , $ stubsMapPath ));
120142 }
121143 }
122144
@@ -127,7 +149,7 @@ private function renamePhp8Stubs(): void
127149 return ;
128150 }
129151
130- $ stubFinder = \ Symfony \ Component \ Finder \ Finder::create ();
152+ $ stubFinder = Finder::create ();
131153 $ stubsMapPath = $ directory . '/../Php8StubsMap.php ' ;
132154 foreach ($ stubFinder ->files ()->name ('*.php ' )->in ($ directory ) as $ stubFile ) {
133155 $ path = $ stubFile ->getPathname ();
@@ -140,26 +162,26 @@ private function renamePhp8Stubs(): void
140162 dirname ($ path ) . '/ ' . $ stubFile ->getBasename ('.php ' ) . '.stub '
141163 );
142164 if ($ renameSuccess === false ) {
143- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not rename %s ' , $ path ));
165+ throw new ShouldNotHappenException (sprintf ('Could not rename %s ' , $ path ));
144166 }
145167 }
146168
147169 $ stubsMapContents = file_get_contents ($ stubsMapPath );
148170 if ($ stubsMapContents === false ) {
149- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not read %s ' , $ stubsMapPath ));
171+ throw new ShouldNotHappenException (sprintf ('Could not read %s ' , $ stubsMapPath ));
150172 }
151173
152174 $ stubsMapContents = str_replace ('.php \', ' , '.stub \', ' , $ stubsMapContents );
153175
154176 $ putSuccess = file_put_contents ($ stubsMapPath , $ stubsMapContents );
155177 if ($ putSuccess === false ) {
156- throw new \ PHPStan \ ShouldNotHappenException (sprintf ('Could not write %s ' , $ stubsMapPath ));
178+ throw new ShouldNotHappenException (sprintf ('Could not write %s ' , $ stubsMapPath ));
157179 }
158180 }
159181
160182 private function patchPhpStormStubs (OutputInterface $ output ): void
161183 {
162- $ stubFinder = \ Symfony \ Component \ Finder \ Finder::create ();
184+ $ stubFinder = Finder::create ();
163185 $ stubsDirectory = __DIR__ . '/../../../vendor/jetbrains/phpstorm-stubs ' ;
164186 foreach ($ stubFinder ->files ()->name ('*.patch ' )->in (__DIR__ . '/../../patches/stubs ' ) as $ patchFile ) {
165187 $ absolutePatchPath = $ patchFile ->getPathname ();
@@ -186,7 +208,7 @@ private function buildPreloadScript(): void
186208
187209%s
188210php;
189- $ finder = \ Symfony \ Component \ Finder \ Finder::create ();
211+ $ finder = Finder::create ();
190212 $ root = realpath (__DIR__ . '/../../.. ' );
191213 if ($ root === false ) {
192214 return ;
@@ -243,7 +265,7 @@ private function transformSource(): void
243265 return ;
244266 }
245267
246- throw new \ PHPStan \ ShouldNotHappenException (implode ("\n" , $ outputLines ));
268+ throw new ShouldNotHappenException (implode ("\n" , $ outputLines ));
247269 }
248270
249271}
0 commit comments