Skip to content

Commit

Permalink
Do not use "strtolower" when there is a dedicated method
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored and ondrejmirtes committed Dec 11, 2022
1 parent f9bfc19 commit bc0a290
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/Rules/PHPUnit/AssertSameBooleanExpectedRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use function count;
use function strtolower;

/**
* @implements Rule<NodeAbstract>
Expand All @@ -35,7 +34,7 @@ public function processNode(Node $node, Scope $scope): array
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || strtolower($node->name->name) !== 'assertsame') {
if (!$node->name instanceof Node\Identifier || $node->name->toLowerString() !== 'assertsame') {
return [];
}

Expand Down
3 changes: 1 addition & 2 deletions src/Rules/PHPUnit/AssertSameNullExpectedRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use function count;
use function strtolower;

/**
* @implements Rule<NodeAbstract>
Expand All @@ -35,7 +34,7 @@ public function processNode(Node $node, Scope $scope): array
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || strtolower($node->name->name) !== 'assertsame') {
if (!$node->name instanceof Node\Identifier || $node->name->toLowerString() !== 'assertsame') {
return [];
}

Expand Down
7 changes: 3 additions & 4 deletions src/Rules/PHPUnit/AssertSameWithCountRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use PHPStan\Rules\Rule;
use PHPStan\Type\ObjectType;
use function count;
use function strtolower;

/**
* @implements Rule<NodeAbstract>
Expand All @@ -36,7 +35,7 @@ public function processNode(Node $node, Scope $scope): array
if (count($node->getArgs()) < 2) {
return [];
}
if (!$node->name instanceof Node\Identifier || strtolower($node->name->name) !== 'assertsame') {
if (!$node->name instanceof Node\Identifier || $node->name->toLowerString() !== 'assertsame') {
return [];
}

Expand All @@ -45,7 +44,7 @@ public function processNode(Node $node, Scope $scope): array
if (
$right instanceof Node\Expr\FuncCall
&& $right->name instanceof Node\Name
&& strtolower($right->name->toString()) === 'count'
&& $right->name->toLowerString() === 'count'
) {
return [
'You should use assertCount($expectedCount, $variable) instead of assertSame($expectedCount, count($variable)).',
Expand All @@ -55,7 +54,7 @@ public function processNode(Node $node, Scope $scope): array
if (
$right instanceof Node\Expr\MethodCall
&& $right->name instanceof Node\Identifier
&& strtolower($right->name->toString()) === 'count'
&& $right->name->toLowerString() === 'count'
&& count($right->getArgs()) === 0
) {
$type = $scope->getType($right->var);
Expand Down
2 changes: 1 addition & 1 deletion src/Rules/PHPUnit/ShouldCallParentMethodsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private function hasParentClassCall(?array $stmts, string $methodName): bool
continue;
}

if (strtolower($stmt->expr->name->name) === $methodName) {
if ($stmt->expr->name->toLowerString() === $methodName) {
return true;
}
}
Expand Down

0 comments on commit bc0a290

Please sign in to comment.