1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Make new InvalidLiteralArgument issue for strpos refs

Ref #4070
This commit is contained in:
Brown 2020-09-10 22:50:47 -04:00 committed by Daniil Gentili
parent 0116284d16
commit 307790fbac
Signed by: danog
GPG Key ID: 8C1BE3B34B230CA7
5 changed files with 26 additions and 1 deletions

View File

@ -231,6 +231,7 @@
<xs:element name="InvalidFunctionCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidGlobal" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidIterator" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidLiteralArgument" type="ArgumentIssueHandlerType" minOccurs="0" />
<xs:element name="InvalidMethodCall" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidNullableReturnType" type="IssueHandlerType" minOccurs="0" />
<xs:element name="InvalidOperand" type="IssueHandlerType" minOccurs="0" />

View File

@ -0,0 +1,11 @@
# InvalidLiteralArgument
Emitted when a scalar value is passed to a method that expected another scalar type
```php
<?php
function foo(string $s) : void {
echo strpos(".", $s);
}
```

View File

@ -1505,6 +1505,10 @@ class Config
return 'InvalidOperand';
}
if ($issue_type === 'InvalidLiteralArgument') {
return 'InvalidArgument';
}
if ($issue_type === 'TraitMethodSignatureMismatch') {
return 'MethodSignatureMismatch';
}

View File

@ -21,6 +21,7 @@ use Psalm\Context;
use Psalm\Issue\ImplicitToStringCast;
use Psalm\Issue\InvalidArgument;
use Psalm\Issue\InvalidScalarArgument;
use Psalm\Issue\InvalidLiteralArgument;
use Psalm\Issue\MixedArgument;
use Psalm\Issue\MixedArgumentTypeCoercion;
use Psalm\Issue\NoValue;
@ -126,7 +127,7 @@ class ArgumentAnalyzer
&& !$arg->value instanceof PhpParser\Node\Expr\ConstFetch
) {
if (IssueBuffer::accepts(
new InvalidArgument(
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),

View File

@ -0,0 +1,8 @@
<?php
namespace Psalm\Issue;
class InvalidLiteralArgument extends ArgumentIssue
{
const ERROR_LEVEL = 4;
const SHORTCODE = 237;
}