Fix InputBag::get (#200)

This commit is contained in:
Vincent Langlet 2021-08-17 08:32:09 +02:00 committed by GitHub
parent 3b455dd263
commit 8a7744a540
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View File

@ -7,9 +7,9 @@ final class InputBag extends ParameterBag
/**
* Returns a string input value by name.
*
* @template D of string|null
* @template D of string|int|float|bool|null
* @psalm-param D $default
* @psalm-return string|D
* @psalm-return string|int|float|bool|D
* @psalm-taint-source input
*/
public function get(string $key, $default = null) {}

View File

@ -11,7 +11,7 @@ Feature: InputBag get return type
use Symfony\Component\HttpFoundation\Request;
"""
Scenario Outline: Return type is string if default argument is string.
Scenario Outline: Return type is not null if default argument is string.
Given I have the following code
"""
class App
@ -24,11 +24,14 @@ Feature: InputBag get return type
}
"""
When I run Psalm
Then I see no errors
Then I see these errors
| Type | Message |
| InvalidScalarArgument | Argument 1 of trim expects string, scalar provided |
Examples:
| property |
| query |
| cookies |
| request |
Scenario Outline: Return type is nullable if default argument is not provided.
Given I have the following code
@ -44,10 +47,11 @@ Feature: InputBag get return type
"""
When I run Psalm
Then I see these errors
| Type | Message |
| PossiblyNullArgument | Argument 1 of trim cannot be null, possibly null value provided |
| Type | Message |
| InvalidScalarArgument | Argument 1 of trim expects string, null\|scalar provided |
And I see no other errors
Examples:
| property |
| query |
| cookies |
| request |