From 12271ac1d4a2118d30d12423829a9fc07f6a5b8f Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 20 Oct 2024 20:27:20 +0200 Subject: [PATCH] POC --- .../Accessory/AccessoryLowercaseStringType.php | 4 +++- .../ImpossibleCheckTypeFunctionCallRuleTest.php | 15 +++++++++++++++ .../PHPStan/Rules/Comparison/data/bug-11799.php | 16 ++++++++++++++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Rules/Comparison/data/bug-11799.php diff --git a/src/Type/Accessory/AccessoryLowercaseStringType.php b/src/Type/Accessory/AccessoryLowercaseStringType.php index fe57034af1..12c59e01f2 100644 --- a/src/Type/Accessory/AccessoryLowercaseStringType.php +++ b/src/Type/Accessory/AccessoryLowercaseStringType.php @@ -110,7 +110,9 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult return $otherType->isSuperTypeOfWithReason($this); } - return (new IsSuperTypeOfResult($otherType->isLowercaseString(), [])) + return (new IsSuperTypeOfResult($otherType->isLowercaseString(), [ + 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 16529f3a74..3971cfb0f0 100644 --- a/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php +++ b/tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php @@ -1102,4 +1102,19 @@ public function testAlwaysTruePregMatch(): void $this->analyse([__DIR__ . '/data/always-true-preg-match.php'], []); } + public function testBug11799(): void + { + $this->checkAlwaysTrueCheckTypeFunctionCall = true; + $this->treatPhpDocTypesAsCertain = true; + $this->analyse([__DIR__ . '/data/bug-11799.php'], [ + [ + "Call to function in_array() with arguments string, array{'publishDate', 'approvedAt', 'allowedValues'} and true will always evaluate to false.", + 11, + "• 'publishDate' is not lowercase. +• 'approvedAt' is not lowercase. +• 'allowedValues' is not lowercase." + ], + ]); + } + } diff --git a/tests/PHPStan/Rules/Comparison/data/bug-11799.php b/tests/PHPStan/Rules/Comparison/data/bug-11799.php new file mode 100644 index 0000000000..9d2b2168b8 --- /dev/null +++ b/tests/PHPStan/Rules/Comparison/data/bug-11799.php @@ -0,0 +1,16 @@ +