From 2de9031c477e1eabe9e26c3412610a45c9b6b14d Mon Sep 17 00:00:00 2001 From: Greg Bowler Date: Thu, 2 Jan 2025 23:56:16 +0000 Subject: [PATCH] Static analysis compatibility with PHP 8.1 and PHP 8.4 * tweak: php 8.1 support * tweak: php 8.4 support * tweak: inherit integers from parent node class * tweak: inherit integers from parent node class * tweak: class definition * tweak: fix node extension issue * tweak: php 8.4 changes * tweak: phpcs ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files * tweak: phpstan ignore node files --- .github/workflows/ci.yml | 11 ++++---- phpstan.neon | 7 ++++++ src/Node.php | 43 ++++++-------------------------- src/Node83.php | 40 +++++++++++++++++++++++++++++ src/Node84.php | 40 +++++++++++++++++++++++++++++ test/phpunit/NodeTest.php | 11 +++++--- test/phpunit/XMLDocumentTest.php | 7 +++++- 7 files changed, 115 insertions(+), 44 deletions(-) create mode 100644 phpstan.neon create mode 100644 src/Node83.php create mode 100644 src/Node84.php diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a3e201e..6bf1a0b9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/checkout@v3 @@ -37,7 +37,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] outputs: coverage: ${{ steps.store-coverage.outputs.coverage_text }} @@ -90,7 +90,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v3 @@ -106,13 +106,14 @@ jobs: with: php_version: ${{ matrix.php }} path: src/ + configuration: phpstan.neon phpmd: runs-on: ubuntu-latest needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v3 @@ -136,7 +137,7 @@ jobs: needs: [ composer ] strategy: matrix: - php: [ 8.1, 8.2, 8.3 ] + php: [ 8.1, 8.2, 8.3, 8.4 ] steps: - uses: actions/download-artifact@v3 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 00000000..5582cf57 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 6 + paths: + - src/ + excludePaths: + - src/Node83.php + - src/Node84.php diff --git a/src/Node.php b/src/Node.php index 712fd411..47ddcda2 100644 --- a/src/Node.php +++ b/src/Node.php @@ -1,39 +1,12 @@ =')) { + class Node extends Node84 { + } +} +else { + class Node extends Node83 { + } } diff --git a/src/Node83.php b/src/Node83.php new file mode 100644 index 00000000..91a2a683 --- /dev/null +++ b/src/Node83.php @@ -0,0 +1,40 @@ +createElement("example"); - self::assertNull($sut->baseURI); + + if(version_compare(PHP_VERSION, "8.4", ">=")) { + self::assertEquals(getcwd() . "/", $sut->baseURI); + } + else { + self::assertNull($sut->baseURI); + } } public function testChildNodesEmpty():void { diff --git a/test/phpunit/XMLDocumentTest.php b/test/phpunit/XMLDocumentTest.php index f31d7712..7d1dffa1 100644 --- a/test/phpunit/XMLDocumentTest.php +++ b/test/phpunit/XMLDocumentTest.php @@ -24,7 +24,12 @@ public function testBodyNullOnXML():void { public function testToStringEmptyXML():void { $sut = new XMLDocument(); - self::assertEquals("\n\n", (string)$sut); + if(version_compare(PHP_VERSION, "8.4", ">=")) { + self::assertEquals("\n\n", (string)$sut); + } + else { + self::assertEquals("\n\n", (string)$sut); + } } public function testPropContentTypeEmpty():void {