Skip to content

Commit

Permalink
"fixed" a few PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
k00ni committed Oct 24, 2024
1 parent aa98fe9 commit 9a75ca2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,19 @@ public static function fromString($responseStr)
throw new Exception('Failed to parse HTTP response status line.');
}

// Process the rest of the header lines
/**
* Process the rest of the header lines
*
* @var array<string,array<mixed>>
*/
$headers = [];
foreach ($headerLines as $line) {
if (preg_match("|^([\w-]+):\s+(.+)$|", $line, $m)) {
$hName = ucwords(strtolower($m[1]));
$hValue = $m[2];

if (isset($headers[$hName])) {
if (!\is_array($headers[$hName])) {
if (false === \is_array($headers[$hName])) {
$headers[$hName] = [$headers[$hName]];
}
$headers[$hName][] = $hValue;
Expand Down
11 changes: 11 additions & 0 deletions lib/ParsedUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,17 @@ public function __construct($uri = null)
{
if (\is_string($uri)) {
if (preg_match(self::URI_REGEX, $uri, $matches)) {
/**
* Without the following "hack", PHPStan would throw the following errors (PHP 8.4):
*
* 74 Offset 2 on array{0: string, 1: string, 2: string, ...} in isset() always exists and is not nullable.
* 80 Offset 4 on array{0: string, 1: string, 2: string, ...} in isset() always exists and is not nullable.
* 86 Offset 5 on array{0: string, 1: string, 2: string, ...} in isset() always exists and is not nullable.
*
* @var array<mixed>
*/
$matches = $matches;

if (!empty($matches[1])) {
$this->scheme = isset($matches[2]) ? $matches[2] : '';
}
Expand Down

0 comments on commit 9a75ca2

Please sign in to comment.