1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Don't report InvalidLiteralArgument for paths

This commit is contained in:
fluffycondor 2023-03-18 00:05:44 +06:00
parent f3e950bac7
commit 9730f2c073
2 changed files with 11 additions and 1 deletions

View File

@ -71,7 +71,9 @@ use function reset;
use function strpos;
use function strtolower;
use function substr;
use function substr_count;
use const DIRECTORY_SEPARATOR;
use const PREG_SPLIT_NO_EMPTY;
/**
@ -174,7 +176,9 @@ class ArgumentAnalyzer
$prev_ord = $ord;
}
if (count($values) < 12 || ($gt_count / count($values)) < 0.8) {
if (substr_count($arg_value_type->getSingleStringLiteral()->value, DIRECTORY_SEPARATOR) <= 2
&& (count($values) < 12 || ($gt_count / count($values)) < 0.8)
) {
IssueBuffer::maybeAdd(
new InvalidLiteralArgument(
'Argument ' . ($argument_offset + 1) . ' of ' . $cased_method_id

View File

@ -262,6 +262,12 @@ class CoreStubsTest extends TestCase
'$c===' => 'false|string',
],
];
yield "str_contains doesn't yield InvalidLiteralArgument for __DIR__" => [
'code' => '<?php
$d = __DIR__;
echo str_contains($d, "psalm");
',
];
}
public function providerInvalidCodeParse(): iterable