Skip to content

Commit 6fe4a97

Browse files
committed
refactor: Improve $http_response_header forward compatibilty to avoid false positives
See php/php-src#19611, keeping the deprecated variable name leads to false positives
1 parent 45d261a commit 6fe4a97

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/JsonSchema/Uri/Retrievers/FileGetContents.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,17 @@ public function retrieve($uri)
5151
}
5252

5353
$this->messageBody = $response;
54+
5455
if (function_exists('http_get_last_response_headers')) {
55-
// Use http_get_last_response_headers() for BC compatibility with PHP 8.5+
56-
// where $http_response_header is deprecated.
57-
$http_response_header = http_get_last_response_headers();
56+
$httpResponseHeaders = http_get_last_response_headers();
57+
} else {
58+
/** @phpstan-ignore nullCoalesce.variable ($http_response_header can non-existing when no request was made) */
59+
$httpResponseHeaders = $http_response_header ?? [];
5860
}
59-
if (!empty($http_response_header)) {
60-
// $http_response_header cannot be tested, because it's defined in the method's local scope
61-
// See http://php.net/manual/en/reserved.variables.httpresponseheader.php for more info.
62-
$this->fetchContentType($http_response_header); // @codeCoverageIgnore
63-
} else { // @codeCoverageIgnore
64-
// Could be a "file://" url or something else - fake up the response
61+
62+
if (!empty($httpResponseHeaders)) {
63+
$this->fetchContentType($httpResponseHeaders);
64+
} else {
6565
$this->contentType = null;
6666
}
6767

@@ -73,7 +73,7 @@ public function retrieve($uri)
7373
*
7474
* @return bool Whether the Content-Type header was found or not
7575
*/
76-
private function fetchContentType(array $headers)
76+
private function fetchContentType(array $headers): bool
7777
{
7878
foreach (array_reverse($headers) as $header) {
7979
if ($this->contentType = self::getContentTypeMatchInHeader($header)) {

0 commit comments

Comments
 (0)