mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
parent
db55f608be
commit
0b66e8897c
@ -1792,7 +1792,7 @@ class AssertionFinder
|
||||
if ($var_type->from_docblock || $other_type->from_docblock) {
|
||||
if (IssueBuffer::accepts(
|
||||
new DocblockTypeContradiction(
|
||||
$var_type . ' can never contain ' . $other_type,
|
||||
$var_type . ' can never contain ' . $other_type->getId(),
|
||||
new CodeLocation($source, $conditional),
|
||||
$var_type . ' ' . $other_type
|
||||
),
|
||||
|
@ -126,16 +126,34 @@ class ArgumentAnalyzer
|
||||
&& !$arg->value instanceof PhpParser\Node\Scalar\MagicConst
|
||||
&& !$arg->value instanceof PhpParser\Node\Expr\ConstFetch
|
||||
) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidLiteralArgument(
|
||||
'Argument ' . ($argument_offset + 1) . ' of ' . $cased_method_id
|
||||
. ' expects a non-literal value, ' . $arg_value_type->getId() . ' provided',
|
||||
new CodeLocation($statements_analyzer->getSource(), $arg->value),
|
||||
$cased_method_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
$values = \preg_split('//u', $arg_value_type->getSingleStringLiteral()->value, null, \PREG_SPLIT_NO_EMPTY);
|
||||
|
||||
$prev_ord = 0;
|
||||
|
||||
$gt_count = 0;
|
||||
|
||||
foreach ($values as $value) {
|
||||
$ord = \mb_ord($value);
|
||||
|
||||
if ($ord > $prev_ord) {
|
||||
$gt_count++;
|
||||
}
|
||||
|
||||
$prev_ord = $ord;
|
||||
}
|
||||
|
||||
if (count($values) < 12 || ($gt_count / count($values)) < 0.8) {
|
||||
if (IssueBuffer::accepts(
|
||||
new InvalidLiteralArgument(
|
||||
'Argument ' . ($argument_offset + 1) . ' of ' . $cased_method_id
|
||||
. ' expects a non-literal value, ' . $arg_value_type->getId() . ' provided',
|
||||
new CodeLocation($statements_analyzer->getSource(), $arg->value),
|
||||
$cased_method_id
|
||||
),
|
||||
$statements_analyzer->getSuppressedIssues()
|
||||
)) {
|
||||
// fall through
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1341,6 +1341,12 @@ class FunctionCallTest extends TestCase
|
||||
return $matches[0];
|
||||
}'
|
||||
],
|
||||
'strposAllowDictionary' => [
|
||||
'<?php
|
||||
function sayHello(string $format): void {
|
||||
if (strpos("abcdefghijklmno", $format)) {}
|
||||
}',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user