From 3088f9490b03e03c76fcdc153f3b4f8dab4d3304 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 20 Oct 2024 20:29:43 +0200 Subject: [PATCH] Fix --- .../ImpossibleCheckTypeFunctionCallRule.php | 1 + .../Comparison/ImpossibleCheckTypeMethodCallRule.php | 3 ++- .../ImpossibleCheckTypeStaticMethodCallRule.php | 2 +- src/Type/Accessory/AccessoryLowercaseStringType.php | 12 +++++++++--- .../ImpossibleCheckTypeFunctionCallRuleTest.php | 2 +- 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php b/src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php index ef90093103..814f10f695 100644 --- a/src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php +++ b/src/Rules/Comparison/ImpossibleCheckTypeFunctionCallRule.php @@ -7,6 +7,7 @@ use PHPStan\Parser\LastConditionVisitor; use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; +use function count; use function sprintf; use function strtolower; diff --git a/src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php b/src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php index 11ed4cbed7..ba80f0e262 100644 --- a/src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php +++ b/src/Rules/Comparison/ImpossibleCheckTypeMethodCallRule.php @@ -10,6 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\ShouldNotHappenException; +use function count; use function sprintf; /** @@ -45,7 +46,7 @@ public function processNode(Node $node, Scope $scope): array } $addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $node, $reasons): RuleErrorBuilder { - if (count($reasons)) { + if (count($reasons) > 0) { return $ruleErrorBuilder->acceptsReasonsTip($reasons); } diff --git a/src/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRule.php b/src/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRule.php index ba2dca4905..95c870a0be 100644 --- a/src/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRule.php +++ b/src/Rules/Comparison/ImpossibleCheckTypeStaticMethodCallRule.php @@ -10,6 +10,7 @@ use PHPStan\Rules\Rule; use PHPStan\Rules\RuleErrorBuilder; use PHPStan\ShouldNotHappenException; +use function count; use function sprintf; /** @@ -46,7 +47,6 @@ public function processNode(Node $node, Scope $scope): array $addTip = function (RuleErrorBuilder $ruleErrorBuilder) use ($scope, $node, $reasons): RuleErrorBuilder { if (count($reasons) > 0) { - var_dump($reasons);die; return $ruleErrorBuilder->acceptsReasonsTip($reasons); } diff --git a/src/Type/Accessory/AccessoryLowercaseStringType.php b/src/Type/Accessory/AccessoryLowercaseStringType.php index 12c59e01f2..ac23e48f37 100644 --- a/src/Type/Accessory/AccessoryLowercaseStringType.php +++ b/src/Type/Accessory/AccessoryLowercaseStringType.php @@ -30,6 +30,7 @@ use PHPStan\Type\Type; use PHPStan\Type\UnionType; use PHPStan\Type\VerbosityLevel; +use function sprintf; class AccessoryLowercaseStringType implements CompoundType, AccessoryType { @@ -110,9 +111,14 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOfWithReason($this); } - return (new IsSuperTypeOfResult($otherType->isLowercaseString(), [ - sprintf("%s is not lowercase.", $otherType->describe(VerbosityLevel::value())), - ])) + $isLowercase = $otherType->isLowercaseString(); + + return (new IsSuperTypeOfResult( + $isLowercase, + $otherType->isString()->yes() && $isLowercase->no() + ? [sprintf("%s is not lowercase.", $otherType->describe(VerbosityLevel::value()))] + : [] + )) ->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe()); } diff --git a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php index 3971cfb0f0..2edb59a477 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -1112,7 +1112,7 @@ public function testBug11799(): void 11, "• 'publishDate' is not lowercase. • 'approvedAt' is not lowercase. -• 'allowedValues' is not lowercase." +• 'allowedValues' is not lowercase.", ], ]); }