Skip to content

Conversation

@staabm
Copy link
Contributor

@staabm staabm commented Dec 19, 2025

before this PR running

➜  phpstan-src git:(2.1.x) ✗ cat foob.php                                                                                             
<?php

function doFoo(A $a)
{

}

➜  phpstan-src git:(2.1.x) ✗ bin/phpstan analyze foob.php --xdebug --debug

 ! [NOTE] You are running with "--xdebug" enabled, and the Xdebug PHP extension is active.                              
 !        The process will halt at breakpoints, but PHPStan will run much slower.                                       
 !        Use this only if you are debugging PHPStan itself or your custom extensions.                                  

Note: Using configuration file /Users/staabm/workspace/phpstan-src/phpstan.neon.dist.
/Users/staabm/workspace/phpstan-src/foob.php
 ------ ------------------------------------------------------ 
  Line   foob.php                                              
 ------ ------------------------------------------------------ 
  3      Function doFoo() has no return type specified.        
         🪪  missingType.return                                
         at foob.php:3                                         
  3      Parameter $a of function doFoo() has invalid type A.  
         🪪  class.notFound                                    
         at foob.php:3                                         
 ------ ------------------------------------------------------ 


                                                                                                                        
 [ERROR] Found 2 errors                                                                                                                                                                                                                    

would invoke FileReader::readFile() 188 times.

after this PR it is only invoked 62 times.

-> we reduce bootstrap overhead when projects have phpstan-phpunit installed
-> similar idea as in phpstan/phpstan-src#4491, refs phpstan/build-infection#16


using phpstan/phpstan-src@38ea1ab

before this PR:

➜  phpstan-src git:(2.1.x) ✗ hyperfine 'bin/phpstan analyze foob.php --debug' -i
Benchmark 1: bin/phpstan analyze foob.php --debug
  Time (mean ± σ):     749.7 ms ±   6.1 ms    [User: 577.5 ms, System: 167.0 ms]
  Range (min … max):   745.0 ms … 762.4 ms    10 runs
 
  Warning: Ignoring non-zero exit code.

after this PR:

➜  phpstan-src git:(2.1.x) ✗ hyperfine 'bin/phpstan analyze foob.php --debug' -i
Benchmark 1: bin/phpstan analyze foob.php --debug
  Time (mean ± σ):     726.2 ms ±  16.3 ms    [User: 550.9 ms, System: 169.2 ms]
  Range (min … max):   715.0 ms … 769.7 ms    10 runs
 
  Warning: Ignoring non-zero exit code.

if ($file !== false) {
$phpUnitRoot = dirname($file, 3);
$phpUnitComposer = $phpUnitRoot . '/composer.json';
if (is_file($phpUnitComposer)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we really need this is_file or could we just drop it, because we already do @file_get_contents($phpUnitComposer); which would swallow the error nevertheless?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be dropped :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we go.

@staabm staabm marked this pull request as ready for review December 19, 2025 08:30
if ($file !== false) {
$phpUnitRoot = dirname($file, 3);
$phpUnitComposer = $phpUnitRoot . '/composer.json';
if (is_file($phpUnitComposer)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be dropped :)

@ondrejmirtes ondrejmirtes merged commit 5e30669 into phpstan:2.0.x Dec 19, 2025
88 checks passed
@ondrejmirtes
Copy link
Member

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants