Skip to content

Commit 798b72f

Browse files
authored
InputBag get stub for return type (#69)
1 parent 9e7968c commit 798b72f

File tree

2 files changed

+79
-0
lines changed

2 files changed

+79
-0
lines changed

src/Stubs/5/InputBag.stubphp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Symfony\Component\HttpFoundation;
4+
5+
final class InputBag extends ParameterBag
6+
{
7+
/**
8+
* Returns a string input value by name.
9+
*
10+
* @template D of string|null
11+
* @psalm-param D $default
12+
* @psalm-return string|D
13+
*/
14+
public function get(string $key, $default = null) {}
15+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
@symfony-5
2+
Feature: InputBag get return type
3+
4+
Background:
5+
Given I have the following config
6+
"""
7+
<?xml version="1.0"?>
8+
<psalm errorLevel="1">
9+
<projectFiles>
10+
<directory name="."/>
11+
</projectFiles>
12+
13+
<plugins>
14+
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
15+
</plugins>
16+
</psalm>
17+
"""
18+
And I have the following code preamble
19+
"""
20+
<?php
21+
22+
use Symfony\Component\HttpFoundation\Request;
23+
"""
24+
25+
Scenario Outline: Return type is string if default argument is string.
26+
Given I have the following code
27+
"""
28+
class App
29+
{
30+
public function __invoke(Request $request): void
31+
{
32+
$string = $request-><property>->get('foo', 'bar');
33+
trim($string);
34+
}
35+
}
36+
"""
37+
When I run Psalm
38+
Then I see no errors
39+
Examples:
40+
| property |
41+
| query |
42+
| cookies |
43+
44+
Scenario Outline: Return type is nullable if default argument is not provided.
45+
Given I have the following code
46+
"""
47+
class App
48+
{
49+
public function __invoke(Request $request): void
50+
{
51+
$nullableString = $request-><property>->get('foo');
52+
trim($nullableString);
53+
}
54+
}
55+
"""
56+
When I run Psalm
57+
Then I see these errors
58+
| Type | Message |
59+
| PossiblyNullArgument | Argument 1 of trim cannot be null, possibly null value provided |
60+
And I see no other errors
61+
Examples:
62+
| property |
63+
| query |
64+
| cookies |

0 commit comments

Comments
 (0)