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

Allow misplaced required params so Psalm still inspects the code

This commit is contained in:
Brown 2019-06-07 09:25:03 -04:00
parent 91c11a0443
commit b00d51b7db
5 changed files with 10 additions and 20 deletions

View File

@ -900,14 +900,6 @@ Emitted when an `@param` entry in a functions docblock doesnt match the pa
function foo(string $b) : void {}
```
### MisplacedRequiredParam
Emitted when a required param is before a param that is not required. Included in Psalm because it is an E_WARNING in PHP
```php
function foo(int $i = 5, string $j) : void {}
```
### MissingClosureParamType
Emitted when a closure parameter has no type information associated with it

View File

@ -1543,18 +1543,10 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
if (!$param->variadic
&& $has_optional_param
&& is_string($param->var->name)
) {
if (IssueBuffer::accepts(
new MisplacedRequiredParam(
'Required param $' . $param->var->name . ' should come before any optional params in ' .
$cased_function_id,
new CodeLocation($this->file_scanner, $param, null, true)
)
)) {
foreach ($storage->params as $param) {
$param->is_optional = false;
}
$storage->has_visitor_issues = true;
}
} else {
$has_optional_param = true;

View File

@ -1,6 +1,9 @@
<?php
namespace Psalm\Issue;
/**
* @psalm-suppress UnusedClass because it's deprecated
*/
class MisplacedRequiredParam extends CodeIssue
{
}

View File

@ -101,6 +101,8 @@ class DocumentationTest extends TestCase
// these are deprecated
$code_blocks['TypeCoercion'] = true;
$code_blocks['MixedTypeCoercion'] = true;
$code_blocks['MixedTypeCoercion'] = true;
$code_blocks['MisplacedRequiredParam'] = true;
$documented_issues = array_keys($code_blocks);
sort($documented_issues);

View File

@ -673,8 +673,9 @@ class MethodSignatureTest extends TestCase
],
'misplacedRequiredParam' => [
'<?php
function foo($bar = null, $bat): void {}',
'error_message' => 'MisplacedRequiredParam',
function foo(string $bar = null, int $bat): void {}
foo();',
'error_message' => 'TooFewArguments',
],
'clasginByRef' => [
'<?php