Skip to content

Commit 12271ac

Browse files
POC
1 parent 902e6c3 commit 12271ac

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/Type/Accessory/AccessoryLowercaseStringType.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ public function isSubTypeOfWithReason(Type $otherType): IsSuperTypeOfResult
110110
return $otherType->isSuperTypeOfWithReason($this);
111111
}
112112

113-
return (new IsSuperTypeOfResult($otherType->isLowercaseString(), []))
113+
return (new IsSuperTypeOfResult($otherType->isLowercaseString(), [
114+
sprintf("%s is not lowercase.", $otherType->describe(VerbosityLevel::value())),
115+
]))
114116
->and($otherType instanceof self ? IsSuperTypeOfResult::createYes() : IsSuperTypeOfResult::createMaybe());
115117
}
116118

tests/PHPStan/Rules/Comparison/ImpossibleCheckTypeFunctionCallRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,4 +1102,19 @@ public function testAlwaysTruePregMatch(): void
11021102
$this->analyse([__DIR__ . '/data/always-true-preg-match.php'], []);
11031103
}
11041104

1105+
public function testBug11799(): void
1106+
{
1107+
$this->checkAlwaysTrueCheckTypeFunctionCall = true;
1108+
$this->treatPhpDocTypesAsCertain = true;
1109+
$this->analyse([__DIR__ . '/data/bug-11799.php'], [
1110+
[
1111+
"Call to function in_array() with arguments string, array{'publishDate', 'approvedAt', 'allowedValues'} and true will always evaluate to false.",
1112+
11,
1113+
"• 'publishDate' is not lowercase.
1114+
• 'approvedAt' is not lowercase.
1115+
• 'allowedValues' is not lowercase."
1116+
],
1117+
]);
1118+
}
1119+
11051120
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace Bug11799;
4+
5+
function getSomeInput(): string { return random_bytes(100); }
6+
7+
function getSortBy(): string
8+
{
9+
$sortBy = mb_strtolower(getSomeInput());
10+
11+
if (! in_array($sortBy, ['publishDate', 'approvedAt', 'allowedValues'], true)) {
12+
// Do something
13+
}
14+
15+
return $sortBy;
16+
}

0 commit comments

Comments
 (0)