-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
InputBag get stub for return type (#69)
- Loading branch information
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\HttpFoundation; | ||
|
||
final class InputBag extends ParameterBag | ||
{ | ||
/** | ||
* Returns a string input value by name. | ||
* | ||
* @template D of string|null | ||
* @psalm-param D $default | ||
* @psalm-return string|D | ||
*/ | ||
public function get(string $key, $default = null) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
@symfony-5 | ||
Feature: InputBag get return type | ||
|
||
Background: | ||
Given I have the following config | ||
""" | ||
<?xml version="1.0"?> | ||
<psalm errorLevel="1"> | ||
<projectFiles> | ||
<directory name="."/> | ||
</projectFiles> | ||
<plugins> | ||
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> | ||
</plugins> | ||
</psalm> | ||
""" | ||
And I have the following code preamble | ||
""" | ||
<?php | ||
use Symfony\Component\HttpFoundation\Request; | ||
""" | ||
|
||
Scenario Outline: Return type is string if default argument is string. | ||
Given I have the following code | ||
""" | ||
class App | ||
{ | ||
public function __invoke(Request $request): void | ||
{ | ||
$string = $request-><property>->get('foo', 'bar'); | ||
trim($string); | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see no errors | ||
Examples: | ||
| property | | ||
| query | | ||
| cookies | | ||
|
||
Scenario Outline: Return type is nullable if default argument is not provided. | ||
Given I have the following code | ||
""" | ||
class App | ||
{ | ||
public function __invoke(Request $request): void | ||
{ | ||
$nullableString = $request-><property>->get('foo'); | ||
trim($nullableString); | ||
} | ||
} | ||
""" | ||
When I run Psalm | ||
Then I see these errors | ||
| Type | Message | | ||
| PossiblyNullArgument | Argument 1 of trim cannot be null, possibly null value provided | | ||
And I see no other errors | ||
Examples: | ||
| property | | ||
| query | | ||
| cookies | |