Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Rules/Comparison/ImpossibleCheckTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ public function getArgumentsDescription(
return '';
}

$descriptions = array_map(fn (Arg $arg): string => ($this->treatPhpDocTypesAsCertain ? $scope->getType($arg->value) : $scope->getNativeType($arg->value))->describe(VerbosityLevel::value()), $args);
$descriptions = array_map(fn (Arg $arg): string => ($this->treatPhpDocTypesAsCertain ? $scope->getType($arg->value) : $scope->getNativeType($arg->value))->describe(VerbosityLevel::precise()), $args);

if (count($descriptions) < 3) {
return sprintf(' with %s', implode(' and ', $descriptions));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ public function testImpossibleCheckTypeFunctionCall(): void
367,
],
[
'Call to function is_string() with mixed will always evaluate to false.',
'Call to function is_string() with mixed~string will always evaluate to false.',
561,
],
[
'Call to function is_callable() with mixed will always evaluate to false.',
'Call to function is_callable() with mixed~callable() will always evaluate to false.',
572,
],
[
'Call to function method_exists() with \'CheckTypeFunctionCall\\\\MethodExists\' and \'testWithStringFirst…\' will always evaluate to true.',
'Call to function method_exists() with \'CheckTypeFunctionCall\\\\MethodExists\' and \'testWithStringFirstArgument\' will always evaluate to true.',
586,
],
[
Expand Down Expand Up @@ -330,11 +330,11 @@ public function testImpossibleCheckTypeFunctionCallWithoutAlwaysTrue(): void
367,
],
[
'Call to function is_string() with mixed will always evaluate to false.',
'Call to function is_string() with mixed~string will always evaluate to false.',
561,
],
[
'Call to function is_callable() with mixed will always evaluate to false.',
'Call to function is_callable() with mixed~callable() will always evaluate to false.',
572,
],
[
Expand Down Expand Up @@ -1102,4 +1102,16 @@ 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 lowercase-string, array{'publishDate', 'approvedAt', 'allowedValues'} and true will always evaluate to false.",
11,
],
]);
}

}
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;
}
Loading