Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7389207

Browse files
Remove nullable type after calling HeaderBag::has
1 parent c55237a commit 7389207

File tree

4 files changed

+30
-6
lines changed

4 files changed

+30
-6
lines changed

‎extension.neon

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,5 +298,14 @@ services:
298298

299299
# InputBag::get() type specification
300300
-
301-
factory: PHPStan\Type\Symfony\InputBagTypeSpecifyingExtension
301+
factory: PHPStan\Type\Symfony\BagTypeSpecifyingExtension
302302
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
303+
arguments:
304+
className: Symfony\Component\HttpFoundation\InputBag
305+
306+
# HeaderBag::get() type specification
307+
-
308+
factory: PHPStan\Type\Symfony\BagTypeSpecifyingExtension
309+
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
310+
arguments:
311+
className: Symfony\Component\HttpFoundation\HeaderBag

‎src/Type/Symfony/InputBagTypeSpecifyingExtension.php renamed to ‎src/Type/Symfony/BagTypeSpecifyingExtension.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,30 @@
1111
use PHPStan\Reflection\MethodReflection;
1212
use PHPStan\Type\MethodTypeSpecifyingExtension;
1313
use PHPStan\Type\NullType;
14-
use Symfony\Component\HttpFoundation\InputBag;
1514

16-
final class InputBagTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
15+
final class BagTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
1716
{
1817

19-
private const INPUT_BAG_CLASS = InputBag::class;
2018
private const HAS_METHOD_NAME = 'has';
2119
private const GET_METHOD_NAME = 'get';
2220

2321
/** @var TypeSpecifier */
2422
private $typeSpecifier;
2523

24+
/** @var class-string */
25+
private $className;
26+
27+
/**
28+
* @param class-string $className
29+
*/
30+
public function __construct(string $className)
31+
{
32+
$this->className = $className;
33+
}
34+
2635
public function getClass(): string
2736
{
28-
return self::INPUT_BAG_CLASS;
37+
return $this->className;
2938
}
3039

3140
public function isMethodSupported(MethodReflection $methodReflection, MethodCall $node, TypeSpecifierContext $context): bool

‎tests/Type/Symfony/ExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ExtensionTest extends TypeInferenceTestCase
1515
public function dataFileAsserts(): iterable
1616
{
1717
yield from $this->gatherAssertTypes(__DIR__ . '/data/envelope_all.php');
18-
yield from $this->gatherAssertTypes(__DIR__ . '/data/header_bag_get.php');
18+
yield from $this->gatherAssertTypes(__DIR__ . '/data/header_bag.php');
1919
yield from $this->gatherAssertTypes(__DIR__ . '/data/response_header_bag_get_cookies.php');
2020

2121
if (class_exists('Symfony\Component\HttpFoundation\InputBag')) {

‎tests/Type/Symfony/data/header_bag_get.php renamed to ‎tests/Type/Symfony/data/header_bag.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44

55
$bag = new \Symfony\Component\HttpFoundation\HeaderBag(['foo' => ['bar']]);
66

7+
if ($bag->has('bar')) {
8+
assertType('string', $bag->get('bar'));
9+
} else {
10+
assertType('null', $bag->get('bar'));
11+
}
12+
713
assertType('string|null', $bag->get('foo'));
814
assertType('string|null', $bag->get('foo', null));
915
assertType('string', $bag->get('foo', 'baz'));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /