Skip to content

Commit fba806d

Browse files
committed
Refactor PHPUnitVersionDetector to ease different major version checks
1 parent dd87f2e commit fba806d

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/Rules/PHPUnit/PHPUnitVersionDetector.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
class 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

Comments
 (0)