Skip to content

Commit

Permalink
Revert "Remove nullable type after calling HeaderBag::has"
Browse files Browse the repository at this point in the history
This reverts commit 7389207.
  • Loading branch information
ondrejmirtes committed Dec 16, 2022
1 parent 7389207 commit 3178f15
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 30 deletions.
11 changes: 1 addition & 10 deletions extension.neon
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,5 @@ services:

# InputBag::get() type specification
-
factory: PHPStan\Type\Symfony\BagTypeSpecifyingExtension
factory: PHPStan\Type\Symfony\InputBagTypeSpecifyingExtension
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
arguments:
className: Symfony\Component\HttpFoundation\InputBag

# HeaderBag::get() type specification
-
factory: PHPStan\Type\Symfony\BagTypeSpecifyingExtension
tags: [phpstan.typeSpecifier.methodTypeSpecifyingExtension]
arguments:
className: Symfony\Component\HttpFoundation\HeaderBag
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,21 @@
use PHPStan\Reflection\MethodReflection;
use PHPStan\Type\MethodTypeSpecifyingExtension;
use PHPStan\Type\NullType;
use Symfony\Component\HttpFoundation\InputBag;

final class BagTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
final class InputBagTypeSpecifyingExtension implements MethodTypeSpecifyingExtension, TypeSpecifierAwareExtension
{

private const INPUT_BAG_CLASS = InputBag::class;
private const HAS_METHOD_NAME = 'has';
private const GET_METHOD_NAME = 'get';

/** @var TypeSpecifier */
private $typeSpecifier;

/** @var class-string */
private $className;

/**
* @param class-string $className
*/
public function __construct(string $className)
{
$this->className = $className;
}

public function getClass(): string
{
return $this->className;
return self::INPUT_BAG_CLASS;
}

public function isMethodSupported(MethodReflection $methodReflection, MethodCall $node, TypeSpecifierContext $context): bool
Expand Down
2 changes: 1 addition & 1 deletion tests/Type/Symfony/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExtensionTest extends TypeInferenceTestCase
public function dataFileAsserts(): iterable
{
yield from $this->gatherAssertTypes(__DIR__ . '/data/envelope_all.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/header_bag.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/header_bag_get.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/response_header_bag_get_cookies.php');

if (class_exists('Symfony\Component\HttpFoundation\InputBag')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

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

if ($bag->has('bar')) {
assertType('string', $bag->get('bar'));
} else {
assertType('null', $bag->get('bar'));
}

assertType('string|null', $bag->get('foo'));
assertType('string|null', $bag->get('foo', null));
assertType('string', $bag->get('foo', 'baz'));
Expand Down

0 comments on commit 3178f15

Please sign in to comment.