phpstan-symfony icon indicating copy to clipboard operation
phpstan-symfony copied to clipboard

Type inference for HeaderBag could support has()

Open Seldaek opened this issue 1 year ago • 0 comments

Right now calling this triggers an error as the returned header is string|null, but really after ->has($key) returns true, we can assert that ->get($sameKey) will be string. At least as long as there is no other impure call made in between like ->remove() or ->replace()

if ($request->headers->has('foo')) {
    $v = strtolower($request->headers->get('foo'));
}

Seldaek avatar Jun 26 '24 10:06 Seldaek