From dfa88cd56ac9f4e4beb774771f52651572e8ec69 Mon Sep 17 00:00:00 2001 From: Konrad Abicht Date: Thu, 24 Oct 2024 14:43:11 +0200 Subject: [PATCH] Introduce PHP 8.4 support (#50) * Tests.yml: added 8.4 as test target * Parser/RdfXml: removed xml_set_object call Usage of xml_set_object is deprecated in PHP 8.4 in favor of using xml_set_* functions with string method names. Because we already do that the xml_set_object call could be removed without any problems. Link to the offical deprecation information for PHP 8.4: https://wiki.php.net/rfc/deprecations_php_8_4#xml_set_object_and_xml_set_handler_with_string_method_names * "fixed" a few PHPStan errors --- .github/workflows/Tests.yml | 4 ++-- lib/Http/Response.php | 8 ++++++-- lib/ParsedUri.php | 11 +++++++++++ lib/Parser/RdfXml.php | 1 - 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index 24bf72e5..fb368d35 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: true matrix: - php-versions: ['8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout @@ -41,7 +41,7 @@ jobs: strategy: fail-fast: true matrix: - php-versions: ['8.0', '8.1', '8.2', '8.3'] + php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4'] steps: - name: Checkout diff --git a/lib/Http/Response.php b/lib/Http/Response.php index 57651fe3..db93db2c 100644 --- a/lib/Http/Response.php +++ b/lib/Http/Response.php @@ -298,7 +298,11 @@ 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> + */ $headers = []; foreach ($headerLines as $line) { if (preg_match("|^([\w-]+):\s+(.+)$|", $line, $m)) { @@ -306,7 +310,7 @@ public static function fromString($responseStr) $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; diff --git a/lib/ParsedUri.php b/lib/ParsedUri.php index a9f9efe2..4cdfdc41 100644 --- a/lib/ParsedUri.php +++ b/lib/ParsedUri.php @@ -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 + */ + $matches = $matches; + if (!empty($matches[1])) { $this->scheme = isset($matches[2]) ? $matches[2] : ''; } diff --git a/lib/Parser/RdfXml.php b/lib/Parser/RdfXml.php index b5822500..e8f3422c 100644 --- a/lib/Parser/RdfXml.php +++ b/lib/Parser/RdfXml.php @@ -94,7 +94,6 @@ protected function initXMLParser() xml_set_element_handler($parser, [$this, 'startElementHandler'], [$this, 'endElementHandler']); xml_set_character_data_handler($parser, [$this, 'cdataHandler']); xml_set_start_namespace_decl_handler($parser, [$this, 'newNamespaceHandler']); - xml_set_object($parser, $this); $this->xmlParser = $parser; } }