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:
parent
91c11a0443
commit
b00d51b7db
@ -900,14 +900,6 @@ Emitted when an `@param` entry in a function’s docblock doesn’t 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
|
||||
|
@ -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;
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
namespace Psalm\Issue;
|
||||
|
||||
/**
|
||||
* @psalm-suppress UnusedClass because it's deprecated
|
||||
*/
|
||||
class MisplacedRequiredParam extends CodeIssue
|
||||
{
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user