Skip to content

Commit 086c0bb

Browse files
committed
use Trinary
1 parent c0c4a01 commit 086c0bb

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/Rules/PHPUnit/DataProviderHelper.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function getDataProviderMethods(
6565
{
6666
yield from $this->yieldDataProviderAnnotations($testMethod, $scope, $classReflection);
6767

68-
if (!$this->PHPUnitVersion->supportsDataProviderAttribute()) {
68+
if (!$this->PHPUnitVersion->supportsDataProviderAttribute()->yes()) {
6969
return;
7070
}
7171

@@ -156,7 +156,11 @@ public function processDataProvider(
156156
->build();
157157
}
158158

159-
if ($deprecationRulesInstalled && $this->PHPUnitVersion->requiresStaticDataProviders() && !$dataProviderMethodReflection->isStatic()) {
159+
if (
160+
$deprecationRulesInstalled
161+
&& $this->PHPUnitVersion->requiresStaticDataProviders()->yes()
162+
&& !$dataProviderMethodReflection->isStatic()
163+
) {
160164
$errorBuilder = RuleErrorBuilder::message(sprintf(
161165
'@dataProvider %s related method must be static in PHPUnit 10 and newer.',
162166
$dataProviderValue,

src/Rules/PHPUnit/PHPUnitVersion.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace PHPStan\Rules\PHPUnit;
44

5+
use PHPStan\TrinaryLogic;
6+
57
class PHPUnitVersion
68
{
79

@@ -12,19 +14,28 @@ public function __construct(?int $majorVersion)
1214
$this->majorVersion = $majorVersion;
1315
}
1416

15-
public function supportsDataProviderAttribute(): bool
17+
public function supportsDataProviderAttribute(): TrinaryLogic
1618
{
17-
return $this->majorVersion !== null && $this->majorVersion >= 10;
19+
if ($this->majorVersion === null) {
20+
return TrinaryLogic::createMaybe();
21+
}
22+
return TrinaryLogic::createFromBoolean($this->majorVersion >= 10);
1823
}
1924

20-
public function supportsTestAttribute(): bool
25+
public function supportsTestAttribute(): TrinaryLogic
2126
{
22-
return $this->majorVersion !== null && $this->majorVersion >= 10;
27+
if ($this->majorVersion === null) {
28+
return TrinaryLogic::createMaybe();
29+
}
30+
return TrinaryLogic::createFromBoolean($this->majorVersion >= 10);
2331
}
2432

25-
public function requiresStaticDataProviders(): bool
33+
public function requiresStaticDataProviders(): TrinaryLogic
2634
{
27-
return $this->majorVersion !== null && $this->majorVersion >= 10;
35+
if ($this->majorVersion === null) {
36+
return TrinaryLogic::createMaybe();
37+
}
38+
return TrinaryLogic::createFromBoolean($this->majorVersion >= 10);
2839
}
2940

3041
}

src/Rules/PHPUnit/TestMethodsHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getTestMethods(ClassReflection $classReflection, Scope $scope):
6363
}
6464
}
6565

66-
if (!$this->PHPUnitVersion->supportsTestAttribute()) {
66+
if ($this->PHPUnitVersion->supportsTestAttribute()->no()) {
6767
continue;
6868
}
6969

0 commit comments

Comments
 (0)