Skip to content

Commit

Permalink
Ensure http_response_header is a list<string>
Browse files Browse the repository at this point in the history
  • Loading branch information
Seldaek committed May 30, 2024
1 parent 57b6434 commit 316630e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2354,7 +2354,7 @@ static function (): void {
$functionReflection !== null
&& in_array($functionReflection->getName(), ['fopen', 'file_get_contents'], true)
) {
$scope = $scope->assignVariable('http_response_header', new ArrayType(new IntegerType(), new StringType()), new ArrayType(new IntegerType(), new StringType()));
$scope = $scope->assignVariable('http_response_header', AccessoryArrayListType::intersectWith(new ArrayType(new IntegerType(), new StringType())), new ArrayType(new IntegerType(), new StringType()));
}

if (
Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/NodeScopeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1441,6 +1441,7 @@ public function dataFileAsserts(): iterable
yield from $this->gatherAssertTypes(__DIR__ . '/data/preserve-large-constant-array.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-9397.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/bug-10080.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/http-response-header.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/impure-error-log.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsy-isset.php');
yield from $this->gatherAssertTypes(__DIR__ . '/data/falsey-coalesce.php');
Expand Down
8 changes: 8 additions & 0 deletions tests/PHPStan/Analyser/data/http-response-header.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

use function PHPStan\Testing\assertType;
use function PHPStan\Testing\assertNativeType;

file_get_contents('https://example.org');
assertType('list<string>', $http_response_header);
assertNativeType('array<int, string>', $http_response_header);

0 comments on commit 316630e

Please sign in to comment.