@@ -52,6 +52,15 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
5252 $ this ->memoryLimit = $ input ->getOption ('memory-limit ' );
5353 $ this ->excludeDirectory = $ input ->getOption ('exclude-dir ' );
5454
55+ // Default to deprecations.
56+ if (!$ this ->isDeprecationsCheck ) {
57+ if (!$ this ->isAnalysisCheck && !$ this ->isStyleCheck ) {
58+ $ this ->isDeprecationsCheck = true ;
59+ } else {
60+ $ this ->isDeprecationsCheck = false ;
61+ }
62+ }
63+
5564 if ($ this ->memoryLimit ) {
5665 $ output ->writeln ("<comment>Memory limit set to $ this ->memoryLimit " , OutputInterface::VERBOSITY_DEBUG );
5766 }
@@ -65,15 +74,6 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
6574 $ output ->writeln ('<comment>Performing code styling checks ' , OutputInterface::VERBOSITY_DEBUG );
6675 }
6776
68- // Default to deprecations.
69- if (!$ this ->isDeprecationsCheck ) {
70- if (!$ this ->isAnalysisCheck && !$ this ->isStyleCheck ) {
71- $ this ->isDeprecationsCheck = true ;
72- } else {
73- $ this ->isDeprecationsCheck = false ;
74- }
75- }
76-
7777 if ($ input ->getOption ('format ' ) === 'json ' ) {
7878 $ input ->setOption ('format ' , 'prettyJson ' );
7979 }
@@ -94,6 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9494 return 1 ;
9595 }
9696
97+ $ output ->writeln (sprintf ('<comment>Analyzing path: %s</comment> ' , $ realPath ), OutputInterface::VERBOSITY_DEBUG );
9798 $ paths [] = $ realPath ;
9899 }
99100
@@ -108,8 +109,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
108109 }
109110
110111 $ drupalFinder ->locateRoot ($ drupalRootCandidate );
111- $ this ->drupalRoot = $ drupalFinder ->getDrupalRoot ();
112- $ this ->vendorRoot = $ drupalFinder ->getVendorDir ();
112+ $ this ->drupalRoot = realpath ( $ drupalFinder ->getDrupalRoot () );
113+ $ this ->vendorRoot = realpath ( $ drupalFinder ->getVendorDir () );
113114
114115 if (!$ this ->drupalRoot ) {
115116 $ output ->writeln (sprintf ('<error>Unable to locate the Drupal root in %s</error> ' , $ drupalRootCandidate ));
@@ -178,36 +179,48 @@ protected function execute(InputInterface $input, OutputInterface $output): int
178179 $ pharPath = \Phar::running ();
179180 if ($ pharPath !== '' ) {
180181 // Running in packaged Phar archive.
181- $ phpstanBin = 'vendor/phpstan/phpstan/phpstan ' ;
182- $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [$ pharPath . '/error-bootstrap.php ' ];
182+ $ phpstanBin = \realpath ( 'vendor/phpstan/phpstan/phpstan.phar ' ) ;
183+ $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [\realpath ( $ pharPath . '/error-bootstrap.php ' ) ];
183184 $ configuration_data ['includes ' ] = [
184- $ pharPath . '/vendor/phpstan/phpstan-deprecation-rules/rules.neon ' ,
185- $ pharPath . '/vendor/mglaman/phpstan-drupal/extension.neon ' ,
185+ \realpath ( $ pharPath . '/vendor/phpstan/phpstan-deprecation-rules/rules.neon ' ) ,
186+ \realpath ( $ pharPath . '/vendor/mglaman/phpstan-drupal/extension.neon ' ) ,
186187 ];
187188 } elseif (file_exists (__DIR__ . '/../../vendor/autoload.php ' )) {
188189 // Running as a project dependency.
189- $ phpstanBin = __DIR__ . '/../../vendor/phpstan/phpstan/phpstan ' ;
190- $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [__DIR__ . '/../../error-bootstrap.php ' ];
190+ $ phpstanBin = \realpath ( __DIR__ . '/../../vendor/phpstan/phpstan/phpstan.phar ' ) ;
191+ $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [\realpath ( __DIR__ . '/../../error-bootstrap.php ' ) ];
191192 $ configuration_data ['includes ' ] = [
192- __DIR__ . '/../../vendor/phpstan/phpstan-deprecation-rules/rules.neon ' ,
193- __DIR__ . '/../../vendor/mglaman/phpstan-drupal/extension.neon ' ,
193+ \realpath ( __DIR__ . '/../../vendor/phpstan/phpstan-deprecation-rules/rules.neon ' ) ,
194+ \realpath ( __DIR__ . '/../../vendor/mglaman/phpstan-drupal/extension.neon ' ) ,
194195 ];
195196 } elseif (file_exists (__DIR__ . '/../../../../autoload.php ' )) {
196197 // Running as a global dependency.
197- $ phpstanBin = __DIR__ . '/../../../../phpstan/phpstan/phpstan ' ;
198- $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [__DIR__ . '/../../error-bootstrap.php ' ];
198+ $ phpstanBin = \realpath ( __DIR__ . '/../../../../phpstan/phpstan/phpstan.phar ' ) ;
199+ $ configuration_data ['parameters ' ]['bootstrapFiles ' ] = [\realpath ( __DIR__ . '/../../error-bootstrap.php ' ) ];
199200 // The phpstan/extension-installer doesn't seem to register.
200201 $ configuration_data ['includes ' ] = [
201- __DIR__ . '/../../../../phpstan/phpstan-deprecation-rules/rules.neon ' ,
202- __DIR__ . '/../../../../mglaman/phpstan-drupal/extension.neon ' ,
202+ \realpath ( __DIR__ . '/../../../../phpstan/phpstan-deprecation-rules/rules.neon ' ) ,
203+ \realpath ( __DIR__ . '/../../../../mglaman/phpstan-drupal/extension.neon ' ) ,
203204 ];
204205 } else {
205206 throw new ShouldNotHappenException ('Could not determine if local or global installation ' );
206207 }
207208
209+ if (!file_exists ($ phpstanBin )) {
210+ $ output ->writeln ('Could not find PHPStan at ' . $ phpstanBin );
211+ return 1 ;
212+ }
213+
214+ if (substr (PHP_OS , 0 , 3 ) == 'WIN ' ) {
215+ $ phpstanBin = "php $ phpstanBin " ;
216+ }
217+
218+ $ output ->writeln (sprintf ('<comment>PHPStan path: %s</comment> ' , $ phpstanBin ), OutputInterface::VERBOSITY_DEBUG );
208219 $ configuration_encoded = Neon::encode ($ configuration_data , Neon::BLOCK );
209220 $ configuration = sys_get_temp_dir () . '/drupal_check_phpstan_ ' . time () . '.neon ' ;
210221 file_put_contents ($ configuration , $ configuration_encoded );
222+ $ configuration = realpath ($ configuration );
223+ $ output ->writeln (sprintf ('<comment>PHPStan configuration path: %s</comment> ' , $ configuration ), OutputInterface::VERBOSITY_DEBUG );
211224
212225 $ output ->writeln ('<comment>PHPStan configuration:</comment> ' , OutputInterface::VERBOSITY_DEBUG );
213226 $ output ->writeln ($ configuration_encoded , OutputInterface::VERBOSITY_DEBUG );
@@ -238,15 +251,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
238251
239252 $ process = new Process ($ command );
240253 $ process ->setTimeout (null );
254+
255+ $ output ->writeln ('<comment>Executing PHPStan</comment> ' , OutputInterface::VERBOSITY_DEBUG );
241256 $ process ->run (static function ($ type , $ buffer ) use ($ output ) {
242257 if (Process::ERR === $ type ) {
243258 $ output ->getErrorOutput ()->write ($ buffer , false , OutputInterface::OUTPUT_RAW );
244259 } else {
245260 $ output ->write ($ buffer , false , OutputInterface::OUTPUT_RAW );
246261 }
247262 });
263+ $ output ->writeln ('<comment>Finished executing PHPStan</comment> ' , OutputInterface::VERBOSITY_DEBUG );
264+ $ output ->writeln ('<comment>Unlinking PHPStan configuration</comment> ' , OutputInterface::VERBOSITY_DEBUG );
248265 unlink ($ configuration );
249266
267+ $ output ->writeln ('<comment>Return PHPStan exit code</comment> ' , OutputInterface::VERBOSITY_DEBUG );
250268 return $ process ->getExitCode ();
251269 }
252270}
0 commit comments