mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Split UntypedParam into MissingParamType and MissingClosureParamType
This commit is contained in:
parent
1c34dbe289
commit
3482ee3b39
@ -22,6 +22,7 @@
|
||||
|
||||
<PropertyNotSetInConstructor errorLevel="info" />
|
||||
<MissingConstructor errorLevel="info" />
|
||||
<UntypedParam errorLevel="info" />
|
||||
<MissingClosureParamType errorLevel="info" />
|
||||
<MissingParamType errorLevel="info" />
|
||||
</issueHandlers>
|
||||
</psalm>
|
||||
|
@ -23,7 +23,8 @@
|
||||
|
||||
<PropertyNotSetInConstructor errorLevel="info" />
|
||||
<MissingConstructor errorLevel="info" />
|
||||
<UntypedParam errorLevel="info" />
|
||||
<MissingClosureParamType errorLevel="info" />
|
||||
<MissingParamType errorLevel="info" />
|
||||
|
||||
<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->
|
||||
|
||||
|
@ -23,7 +23,8 @@
|
||||
|
||||
<PropertyNotSetInConstructor errorLevel="info" />
|
||||
<MissingConstructor errorLevel="info" />
|
||||
<UntypedParam errorLevel="info" />
|
||||
<MissingClosureParamType errorLevel="info" />
|
||||
<MissingParamType errorLevel="info" />
|
||||
|
||||
<!-- level 4 issues - points to possible deficiencies in logic, higher false-positives -->
|
||||
|
||||
|
@ -141,9 +141,11 @@
|
||||
<xs:element name="MisplacedRequiredParam" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MismatchingDocblockParamType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MismatchingDocblockReturnType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingClosureParamType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingClosureReturnType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingConstructor" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingFile" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingParamType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingPropertyType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingReturnType" type="IssueHandlerType" minOccurs="0" />
|
||||
<xs:element name="MissingDocblockType" type="IssueHandlerType" minOccurs="0" />
|
||||
|
@ -22,7 +22,9 @@ use Psalm\Issue\LessSpecificReturnType;
|
||||
use Psalm\Issue\MethodSignatureMismatch;
|
||||
use Psalm\Issue\MismatchingDocblockParamType;
|
||||
use Psalm\Issue\MismatchingDocblockReturnType;
|
||||
use Psalm\Issue\MissingClosureParamType;
|
||||
use Psalm\Issue\MissingClosureReturnType;
|
||||
use Psalm\Issue\MissingParamType;
|
||||
use Psalm\Issue\MissingReturnType;
|
||||
use Psalm\Issue\MixedInferredReturnType;
|
||||
use Psalm\Issue\MoreSpecificImplementedParamType;
|
||||
@ -30,7 +32,6 @@ use Psalm\Issue\MoreSpecificImplementedReturnType;
|
||||
use Psalm\Issue\MoreSpecificReturnType;
|
||||
use Psalm\Issue\OverriddenMethodAccess;
|
||||
use Psalm\Issue\ReservedWord;
|
||||
use Psalm\Issue\UntypedParam;
|
||||
use Psalm\Issue\UnusedParam;
|
||||
use Psalm\IssueBuffer;
|
||||
use Psalm\StatementsSource;
|
||||
@ -525,13 +526,23 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo
|
||||
? ', ' . ($possible_type ? 'should be ' . $possible_type : 'could not infer type')
|
||||
: '';
|
||||
|
||||
IssueBuffer::accepts(
|
||||
new UntypedParam(
|
||||
'Parameter $' . $function_param->name . ' has no provided type' . $infer_text,
|
||||
$function_param->location
|
||||
),
|
||||
$storage->suppressed_issues
|
||||
);
|
||||
if ($this->function instanceof Closure) {
|
||||
IssueBuffer::accepts(
|
||||
new MissingClosureParamType(
|
||||
'Parameter $' . $function_param->name . ' has no provided type' . $infer_text,
|
||||
$function_param->location
|
||||
),
|
||||
$storage->suppressed_issues
|
||||
);
|
||||
} else {
|
||||
IssueBuffer::accepts(
|
||||
new MissingParamType(
|
||||
'Parameter $' . $function_param->name . ' has no provided type' . $infer_text,
|
||||
$function_param->location
|
||||
),
|
||||
$storage->suppressed_issues
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
6
src/Psalm/Issue/MissingClosureParamType.php
Normal file
6
src/Psalm/Issue/MissingClosureParamType.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class MissingClosureParamType extends CodeIssue
|
||||
{
|
||||
}
|
6
src/Psalm/Issue/MissingParamType.php
Normal file
6
src/Psalm/Issue/MissingParamType.php
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class MissingParamType extends CodeIssue
|
||||
{
|
||||
}
|
@ -1,6 +0,0 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
class UntypedParam extends CodeIssue
|
||||
{
|
||||
}
|
@ -558,7 +558,7 @@ class AnnotationTest extends TestCase
|
||||
function fooFoo($a): void {
|
||||
echo substr($a, 4, 2);
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be string',
|
||||
'error_levels' => ['MixedArgument'],
|
||||
],
|
||||
@ -567,7 +567,7 @@ class AnnotationTest extends TestCase
|
||||
function fooFoo($a): void {
|
||||
echo $a . "foo";
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be string',
|
||||
'error_levels' => ['MixedOperand'],
|
||||
],
|
||||
@ -576,7 +576,7 @@ class AnnotationTest extends TestCase
|
||||
function fooFoo($a): void {
|
||||
echo $a + 5;
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be int|float',
|
||||
'error_levels' => ['MixedOperand', 'MixedArgument'],
|
||||
],
|
||||
@ -585,7 +585,7 @@ class AnnotationTest extends TestCase
|
||||
function fooFoo($a): void {
|
||||
echo $a / 5;
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be int|float',
|
||||
'error_levels' => ['MixedOperand', 'MixedArgument'],
|
||||
],
|
||||
@ -594,7 +594,7 @@ class AnnotationTest extends TestCase
|
||||
function fooFoo($a): void {
|
||||
echo "$a";
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be string',
|
||||
'error_levels' => ['MixedOperand'],
|
||||
],
|
||||
@ -607,7 +607,7 @@ class AnnotationTest extends TestCase
|
||||
echo substr("hello", $a, 2);
|
||||
}
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:2 - Parameter $a has no provided type,'
|
||||
. ' should be int|string',
|
||||
'error_levels' => ['MixedArgument'],
|
||||
],
|
||||
@ -620,7 +620,7 @@ class AnnotationTest extends TestCase
|
||||
class B extends A {
|
||||
public function foo($a): void {}
|
||||
}',
|
||||
'error_message' => 'UntypedParam',
|
||||
'error_message' => 'MissingParamType',
|
||||
'error_levels' => ['MethodSignatureMismatch'],
|
||||
],
|
||||
'alreadyHasCheck' => [
|
||||
@ -630,7 +630,7 @@ class AnnotationTest extends TestCase
|
||||
function shouldTakeString($s): void {
|
||||
if (is_string($s)) takesString($s);
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:4 - Parameter $s has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:4 - Parameter $s has no provided type,'
|
||||
. ' could not infer',
|
||||
'error_levels' => ['MixedArgument'],
|
||||
],
|
||||
@ -645,7 +645,7 @@ class AnnotationTest extends TestCase
|
||||
$s = returnsMixed();
|
||||
takesString($s);
|
||||
}',
|
||||
'error_message' => 'UntypedParam - src/somefile.php:7 - Parameter $s has no provided type,'
|
||||
'error_message' => 'MissingParamType - src/somefile.php:7 - Parameter $s has no provided type,'
|
||||
. ' could not infer',
|
||||
'error_levels' => ['MixedArgument', 'InvalidReturnType', 'MixedAssignment'],
|
||||
],
|
||||
|
@ -195,7 +195,12 @@ class FunctionCallTest extends TestCase
|
||||
}
|
||||
);',
|
||||
'assertions' => [],
|
||||
'error_levels' => ['MixedArrayAccess', 'MixedArgument', 'UntypedParam', 'MissingClosureReturnType'],
|
||||
'error_levels' => [
|
||||
'MixedArrayAccess',
|
||||
'MixedArgument',
|
||||
'MissingClosureParamType',
|
||||
'MissingClosureReturnType',
|
||||
],
|
||||
],
|
||||
'byRefAfterCallable' => [
|
||||
'<?php
|
||||
@ -393,7 +398,7 @@ class FunctionCallTest extends TestCase
|
||||
'$a' => 'array<int, string>',
|
||||
],
|
||||
'error_levels' => [
|
||||
'UntypedParam',
|
||||
'MissingClosureParamType',
|
||||
],
|
||||
],
|
||||
'arrayFilterUseKey' => [
|
||||
@ -535,7 +540,7 @@ class FunctionCallTest extends TestCase
|
||||
*/
|
||||
function f($p, $p) {}',
|
||||
'error_message' => 'DuplicateParam',
|
||||
'error_levels' => ['UntypedParam'],
|
||||
'error_levels' => ['MissingParamType'],
|
||||
],
|
||||
'invalidParamDefault' => [
|
||||
'<?php
|
||||
|
Loading…
Reference in New Issue
Block a user