1313class PHPUnitVersionDetector
1414{
1515
16- private ?bool $ is10OrNewer = null ;
16+ private ?int $ majorVersion = null ;
1717
1818 private ReflectionProvider $ reflectionProvider ;
1919
@@ -24,11 +24,16 @@ public function __construct(ReflectionProvider $reflectionProvider)
2424
2525 public function isPHPUnit10OrNewer (): bool
2626 {
27- if ($ this ->is10OrNewer !== null ) {
28- return $ this ->is10OrNewer ;
27+ return $ this ->getMajorVersion () >= 10 ;
28+ }
29+
30+ private function getMajorVersion (): int
31+ {
32+ if ($ this ->majorVersion !== null ) {
33+ return $ this ->majorVersion ;
2934 }
3035
31- $ this ->is10OrNewer = false ;
36+ $ this ->majorVersion = 9 ;
3237 if ($ this ->reflectionProvider ->hasClass (TestCase::class)) {
3338 $ testCase = $ this ->reflectionProvider ->getClass (TestCase::class);
3439 $ file = $ testCase ->getFileName ();
@@ -41,17 +46,14 @@ public function isPHPUnit10OrNewer(): bool
4146 $ json = json_decode ($ composerJson , true );
4247 $ version = $ json ['extra ' ]['branch-alias ' ]['dev-main ' ] ?? null ;
4348 if ($ version !== null ) {
44- $ majorVersion = (int ) explode ('. ' , $ version )[0 ];
45- if ($ majorVersion >= 10 ) {
46- $ this ->is10OrNewer = true ;
47- }
49+ $ this ->majorVersion = (int ) explode ('. ' , $ version )[0 ];
4850 }
4951 }
5052 }
5153 }
5254 }
5355
54- return $ this ->is10OrNewer ;
56+ return $ this ->majorVersion ;
5557 }
5658
5759}
0 commit comments