Skip to content

Commit d96b5a4

Browse files
committed
Modernize rules with RuleErrorBuilder
1 parent d8bdab0 commit d96b5a4

5 files changed

+13
-13
lines changed

Diff for: src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\NodeAbstract;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011
use function count;
1112

1213
/**
@@ -40,13 +41,13 @@ public function processNode(Node $node, Scope $scope): array
4041

4142
if ($expectedArgumentValue->name->toLowerString() === 'true') {
4243
return [
43-
'You should use assertTrue() instead of assertSame() when expecting "true"',
44+
RuleErrorBuilder::message('You should use assertTrue() instead of assertSame() when expecting "true"')->build(),
4445
];
4546
}
4647

4748
if ($expectedArgumentValue->name->toLowerString() === 'false') {
4849
return [
49-
'You should use assertFalse() instead of assertSame() when expecting "false"',
50+
RuleErrorBuilder::message('You should use assertFalse() instead of assertSame() when expecting "false"')->build(),
5051
];
5152
}
5253

Diff for: src/Rules/PHPUnit/AssertSameNullExpectedRule.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\NodeAbstract;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011
use function count;
1112

1213
/**
@@ -40,7 +41,7 @@ public function processNode(Node $node, Scope $scope): array
4041

4142
if ($expectedArgumentValue->name->toLowerString() === 'null') {
4243
return [
43-
'You should use assertNull() instead of assertSame(null, $actual).',
44+
RuleErrorBuilder::message('You should use assertNull() instead of assertSame(null, $actual).')->build(),
4445
];
4546
}
4647

Diff for: src/Rules/PHPUnit/AssertSameWithCountRule.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\NodeAbstract;
88
use PHPStan\Analyser\Scope;
99
use PHPStan\Rules\Rule;
10+
use PHPStan\Rules\RuleErrorBuilder;
1011
use PHPStan\Type\ObjectType;
1112
use function count;
1213

@@ -42,7 +43,7 @@ public function processNode(Node $node, Scope $scope): array
4243
&& $right->name->toLowerString() === 'count'
4344
) {
4445
return [
45-
'You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).',
46+
RuleErrorBuilder::message('You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).')->build(),
4647
];
4748
}
4849

@@ -56,7 +57,7 @@ public function processNode(Node $node, Scope $scope): array
5657

5758
if ((new ObjectType(Countable::class))->isSuperTypeOf($type)->yes()) {
5859
return [
59-
'You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()).',
60+
RuleErrorBuilder::message('You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, $variable->count()).')->build(),
6061
];
6162
}
6263
}

Diff for: src/Rules/PHPUnit/ClassMethodCoversExistsRule.php

-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ public function processNode(Node $node, Scope $scope): array
6262
return [];
6363
}
6464

65-
$errors = [];
6665
$classPhpDoc = $classReflection->getResolvedPhpDoc();
6766
[$classCovers, $classCoversDefaultClasses] = $this->coversHelper->getCoverAnnotations($classPhpDoc);
6867

Diff for: src/Rules/PHPUnit/MockMethodCallRule.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use PhpParser\Node\Expr\MethodCall;
77
use PHPStan\Analyser\Scope;
88
use PHPStan\Rules\Rule;
9+
use PHPStan\Rules\RuleErrorBuilder;
910
use PHPUnit\Framework\MockObject\Builder\InvocationMocker;
1011
use PHPUnit\Framework\MockObject\MockObject;
1112
use PHPUnit\Framework\MockObject\Stub;
@@ -28,9 +29,6 @@ public function getNodeType(): string
2829

2930
public function processNode(Node $node, Scope $scope): array
3031
{
31-
/** @var Node\Expr\MethodCall $node */
32-
$node = $node;
33-
3432
if (!$node->name instanceof Node\Identifier || $node->name->name !== 'method') {
3533
return [];
3634
}
@@ -63,11 +61,11 @@ public function processNode(Node $node, Scope $scope): array
6361
continue;
6462
}
6563

66-
$errors[] = sprintf(
64+
$errors[] = RuleErrorBuilder::message(sprintf(
6765
'Trying to mock an undefined method %s() on class %s.',
6866
$method,
6967
implode('&', $mockClasses)
70-
);
68+
))->build();
7169
continue;
7270
}
7371

@@ -81,11 +79,11 @@ public function processNode(Node $node, Scope $scope): array
8179
continue;
8280
}
8381

84-
$errors[] = sprintf(
82+
$errors[] = RuleErrorBuilder::message(sprintf(
8583
'Trying to mock an undefined method %s() on class %s.',
8684
$method,
8785
implode('|', $classNames)
88-
);
86+
))->build();
8987
}
9088

9189
return $errors;

0 commit comments

Comments
 (0)