From b16cd91299f25533da3c9f5a301b1655d9c66a34 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 25 Jul 2024 12:32:12 +0545 Subject: [PATCH 1/2] Add PHP 8.4 support for 2.2 branch --- .github/workflows/ci.yml | 10 ++++++++-- lib/LibXMLException.php | 2 +- lib/Reader.php | 4 ++-- lib/Service.php | 8 ++++---- phpstan.neon | 1 + 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b3d0948..9266a83 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,10 +14,16 @@ jobs: matrix: php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3'] coverage: ['pcov'] + code-style: ['no'] code-analysis: ['no'] include: - php-versions: '7.1' coverage: 'none' + code-style: 'yes' + code-analysis: 'yes' + - php-versions: '8.4' + coverage: 'pcov' + code-style: 'no' code-analysis: 'yes' steps: - name: Checkout @@ -48,8 +54,8 @@ jobs: run: composer install --no-progress --prefer-dist --optimize-autoloader - name: Code Analysis (PHP CS-Fixer) - if: matrix.code-analysis == 'yes' - run: php vendor/bin/php-cs-fixer fix --dry-run --diff + if: matrix.code-style == 'yes' + run: PHP_CS_FIXER_IGNORE_ENV=true php vendor/bin/php-cs-fixer fix --dry-run --diff - name: Code Analysis (PHPStan) if: matrix.code-analysis == 'yes' diff --git a/lib/LibXMLException.php b/lib/LibXMLException.php index fb074f9..2c1bd62 100644 --- a/lib/LibXMLException.php +++ b/lib/LibXMLException.php @@ -33,7 +33,7 @@ class LibXMLException extends ParseException * @param LibXMLError[] $errors * @param Throwable $previousException */ - public function __construct(array $errors, int $code = 0, Throwable $previousException = null) + public function __construct(array $errors, int $code = 0, ?Throwable $previousException = null) { $this->errors = $errors; parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException); diff --git a/lib/Reader.php b/lib/Reader.php index 7871a74..8b22d93 100644 --- a/lib/Reader.php +++ b/lib/Reader.php @@ -103,7 +103,7 @@ public function parse(): array * If the $elementMap argument is specified, the existing elementMap will * be overridden while parsing the tree, and restored after this process. */ - public function parseGetElements(array $elementMap = null): array + public function parseGetElements(?array $elementMap = null): array { $result = $this->parseInnerTree($elementMap); if (!is_array($result)) { @@ -126,7 +126,7 @@ public function parseGetElements(array $elementMap = null): array * * @return array|string|null */ - public function parseInnerTree(array $elementMap = null) + public function parseInnerTree(?array $elementMap = null) { $text = null; $elements = []; diff --git a/lib/Service.php b/lib/Service.php index a8e34d2..1c0f7ad 100644 --- a/lib/Service.php +++ b/lib/Service.php @@ -109,7 +109,7 @@ public function getWriter(): Writer * * @return array|object|string */ - public function parse($input, string $contextUri = null, string &$rootElementName = null) + public function parse($input, ?string $contextUri = null, ?string &$rootElementName = null) { if (is_resource($input)) { // Unfortunately the XMLReader doesn't support streams. When it @@ -153,7 +153,7 @@ public function parse($input, string $contextUri = null, string &$rootElementNam * * @return array|object|string */ - public function expect($rootElementName, $input, string $contextUri = null) + public function expect($rootElementName, $input, ?string $contextUri = null) { if (is_resource($input)) { // Unfortunately the XMLReader doesn't support streams. When it @@ -204,7 +204,7 @@ public function expect($rootElementName, $input, string $contextUri = null) * * @return string */ - public function write(string $rootElementName, $value, string $contextUri = null) + public function write(string $rootElementName, $value, ?string $contextUri = null) { $w = $this->getWriter(); $w->openMemory(); @@ -266,7 +266,7 @@ public function mapValueObject(string $elementName, string $className) * * @throws \InvalidArgumentException */ - public function writeValueObject($object, string $contextUri = null) + public function writeValueObject($object, ?string $contextUri = null) { if (!isset($this->valueObjectMap[get_class($object)])) { throw new \InvalidArgumentException('"'.get_class($object).'" is not a registered value object class. Register your class with mapValueObject.'); diff --git a/phpstan.neon b/phpstan.neon index a28ed62..26b6879 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -1,5 +1,6 @@ parameters: level: 5 + reportUnmatchedIgnoredErrors: false ignoreErrors: - message: '!Parameter #3 \$namespace of method XMLWriter::startElementNs\(\) expects string, null given.!' From 44d0553ebe12ff54589e5f3c71f6f0c48525ba55 Mon Sep 17 00:00:00 2001 From: Phil Davis Date: Thu, 25 Jul 2024 13:29:01 +0545 Subject: [PATCH 2/2] Bump phpunit 9 to at least 9.6 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 4524cf5..b96587b 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "~2.17.1", "phpstan/phpstan": "^0.12", - "phpunit/phpunit" : "^7.5 || ^8.5 || ^9.0" + "phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6" }, "scripts": { "phpstan": [