File tree Expand file tree Collapse file tree 2 files changed +79
-0
lines changed
tests/acceptance/acceptance Expand file tree Collapse file tree 2 files changed +79
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 |
You can’t perform that action at this time.
0 commit comments