Skip to content

Commit

Permalink
InputBag get stub for return type (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
seferov authored Aug 4, 2020
1 parent 9e7968c commit 798b72f
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Stubs/5/InputBag.stubphp
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) {}
}
64 changes: 64 additions & 0 deletions tests/acceptance/acceptance/InputBag.feature
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 |

0 comments on commit 798b72f

Please sign in to comment.