Skip to content

Commit

Permalink
POC
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Oct 20, 2024
1 parent 902e6c3 commit 12271ac
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/Type/Accessory/AccessoryLowercaseStringType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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."
],
]);
}

}
16 changes: 16 additions & 0 deletions tests/PHPStan/Rules/Comparison/data/bug-11799.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php declare(strict_types = 1);

namespace Bug11799;

function getSomeInput(): string { return random_bytes(100); }

function getSortBy(): string
{
$sortBy = mb_strtolower(getSomeInput());

if (! in_array($sortBy, ['publishDate', 'approvedAt', 'allowedValues'], true)) {
// Do something
}

return $sortBy;
}

0 comments on commit 12271ac

Please sign in to comment.