Skip to content

Commit

Permalink
Introduce PHP 8.4 support (#50)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
k00ni authored Oct 24, 2024
1 parent 196b82e commit dfa88cd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
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
1 change: 0 additions & 1 deletion lib/Parser/RdfXml.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down

0 comments on commit dfa88cd

Please sign in to comment.