Skip to content

Commit 7dd505d

Browse files
committed
fix: review comments
1 parent 2ebfd12 commit 7dd505d

4 files changed

Lines changed: 12 additions & 27 deletions

File tree

‎rules.neon‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ conditionalTags:
1313
PHPStan\Rules\PHPUnit\AssertEqualsIsDiscouragedRule:
1414
phpstan.rules.rule: [%strictRulesInstalled%, %featureToggles.bleedingEdge%]
1515
PHPStan\Rules\PHPUnit\AssertEmptyIsDiscouragedRule:
16-
phpstan.rules.rule: %strictRulesInstalled%
16+
phpstan.rules.rule: [%strictRulesInstalled%, %featureToggles.bleedingEdge%]
1717

1818
PHPStan\Rules\PHPUnit\DataProviderDataRule:
1919
phpstan.rules.rule: %featureToggles.bleedingEdge%

‎src/Rules/PHPUnit/AssertEmptyIsDiscouragedRule.php‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,12 @@
88
use PhpParser\Node\Expr\MethodCall;
99
use PhpParser\Node\Expr\StaticCall;
1010
use PhpParser\Node\Identifier;
11-
use PhpParser\Node\Name;
1211
use PHPStan\Analyser\Scope;
1312
use PHPStan\Rules\Rule;
1413
use PHPStan\Rules\RuleErrorBuilder;
1514
use function count;
1615
use function in_array;
1716
use function sprintf;
18-
use function strtolower;
1917

2018
/**
2119
* @implements Rule<CallLike>
@@ -34,26 +32,19 @@ public function processNode(Node $node, Scope $scope): array
3432
return [];
3533
}
3634

37-
if ($node instanceof MethodCall || $node instanceof StaticCall) {
38-
if (!$node->name instanceof Identifier || !in_array($node->name->toLowerString(), ['assertempty', 'assertnotempty'], true)) {
39-
return [];
40-
}
41-
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
42-
return [];
43-
}
44-
} elseif ($node instanceof FuncCall) {
45-
if (!$node->name instanceof Name || !in_array(strtolower($scope->resolveName($node->name)), ['phpunit\\framework\\assertempty', 'phpunit\\framework\\assertnotempty'], true)) {
46-
return [];
47-
}
48-
} else {
35+
if (!($node instanceof MethodCall) && !($node instanceof StaticCall)) {
36+
return [];
37+
}
38+
39+
if (!$node->name instanceof Identifier || !in_array($node->name->toLowerString(), ['assertempty', 'assertnotempty'], true)) {
40+
return [];
41+
}
42+
if (!AssertRuleHelper::isMethodOrStaticCallOnAssert($node, $scope)) {
4943
return [];
5044
}
5145

5246
return [
53-
RuleErrorBuilder::message(sprintf(
54-
'%s() is not allowed. Use more strict assertion.',
55-
$node instanceof FuncCall ? $node->name->getLast() : $node->name->toString(),
56-
))
47+
RuleErrorBuilder::message(sprintf('%s() is not allowed. Use more strict assertion.', $node->name->toString()))
5748
->identifier('empty.notAllowed')
5849
->build(),
5950
];

‎tests/Rules/PHPUnit/AssertEmptyIsDiscouragedRuleTest.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@ final class AssertEmptyIsDiscouragedRuleTest extends RuleTestCase
1414
public function testRule(): void
1515
{
1616
$this->analyse([__DIR__ . '/data/assert-empty-is-discouraged.php'], [
17+
['assertEmpty() is not allowed. Use more strict assertion.', 13],
18+
['assertNotEmpty() is not allowed. Use more strict assertion.', 14],
1719
['assertEmpty() is not allowed. Use more strict assertion.', 15],
1820
['assertNotEmpty() is not allowed. Use more strict assertion.', 16],
19-
['assertEmpty() is not allowed. Use more strict assertion.', 17],
20-
['assertNotEmpty() is not allowed. Use more strict assertion.', 18],
21-
['assertEmpty() is not allowed. Use more strict assertion.', 19],
22-
['assertNotEmpty() is not allowed. Use more strict assertion.', 20],
2321
]);
2422
}
2523

‎tests/Rules/PHPUnit/data/assert-empty-is-discouraged.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use PHPUnit\Framework\Assert;
66
use PHPUnit\Framework\TestCase;
7-
use function PHPUnit\Framework\assertEmpty;
8-
use function PHPUnit\Framework\assertNotEmpty;
97

108
final class AssertEmptyTest extends TestCase
119
{
@@ -16,8 +14,6 @@ public function test(): void
1614
$this->assertNotEmpty([1]);
1715
Assert::assertEmpty([]);
1816
static::assertNotEmpty([1]);
19-
assertEmpty([]);
20-
assertNotEmpty([1]);
2117
}
2218

2319
}

0 commit comments

Comments
 (0)