Skip to content

Commit 2de9031

Browse files
author
Greg Bowler
authored
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
1 parent 6548066 commit 2de9031

File tree

7 files changed

+115
-44
lines changed

7 files changed

+115
-44
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
php: [ 8.1, 8.2, 8.3 ]
10+
php: [ 8.1, 8.2, 8.3, 8.4 ]
1111

1212
steps:
1313
- uses: actions/checkout@v3
@@ -37,7 +37,7 @@ jobs:
3737
needs: [ composer ]
3838
strategy:
3939
matrix:
40-
php: [ 8.1, 8.2, 8.3 ]
40+
php: [ 8.1, 8.2, 8.3, 8.4 ]
4141

4242
outputs:
4343
coverage: ${{ steps.store-coverage.outputs.coverage_text }}
@@ -90,7 +90,7 @@ jobs:
9090
needs: [ composer ]
9191
strategy:
9292
matrix:
93-
php: [ 8.1, 8.2, 8.3 ]
93+
php: [ 8.1, 8.2, 8.3, 8.4 ]
9494

9595
steps:
9696
- uses: actions/download-artifact@v3
@@ -106,13 +106,14 @@ jobs:
106106
with:
107107
php_version: ${{ matrix.php }}
108108
path: src/
109+
configuration: phpstan.neon
109110

110111
phpmd:
111112
runs-on: ubuntu-latest
112113
needs: [ composer ]
113114
strategy:
114115
matrix:
115-
php: [ 8.1, 8.2, 8.3 ]
116+
php: [ 8.1, 8.2, 8.3, 8.4 ]
116117

117118
steps:
118119
- uses: actions/download-artifact@v3
@@ -136,7 +137,7 @@ jobs:
136137
needs: [ composer ]
137138
strategy:
138139
matrix:
139-
php: [ 8.1, 8.2, 8.3 ]
140+
php: [ 8.1, 8.2, 8.3, 8.4 ]
140141

141142
steps:
142143
- uses: actions/download-artifact@v3

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src/
5+
excludePaths:
6+
- src/Node83.php
7+
- src/Node84.php

src/Node.php

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,12 @@
11
<?php
2+
// phpcs:ignoreFile
23
namespace Gt\Dom;
34

4-
use DOMNode;
5-
6-
class Node extends DOMNode {
7-
use NonDocumentTypeChildNode;
8-
use ChildNode;
9-
use ParentNode;
10-
use RegisteredNodeClass;
11-
12-
const TYPE_ELEMENT = XML_ELEMENT_NODE;
13-
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
14-
const TYPE_TEXT = XML_TEXT_NODE;
15-
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
16-
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
17-
const TYPE_ENTITY = XML_ENTITY_NODE;
18-
const TYPE_PI = XML_PI_NODE;
19-
const TYPE_COMMENT = XML_COMMENT_NODE;
20-
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
21-
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
22-
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
23-
const TYPE_NOTATION = XML_NOTATION_NODE;
24-
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
25-
const TYPE_DTD = XML_DTD_NODE;
26-
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
27-
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
28-
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
29-
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
30-
31-
public const DOCUMENT_POSITION_DISCONNECTED = 0b000001;
32-
public const DOCUMENT_POSITION_PRECEDING = 0b000010;
33-
public const DOCUMENT_POSITION_FOLLOWING = 0b000100;
34-
public const DOCUMENT_POSITION_CONTAINS = 0b001000;
35-
public const DOCUMENT_POSITION_CONTAINED_BY = 0b010000;
36-
public const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0b100000;
37-
38-
private function __construct() {}
5+
if (version_compare(PHP_VERSION, '8.4', '>=')) {
6+
class Node extends Node84 {
7+
}
8+
}
9+
else {
10+
class Node extends Node83 {
11+
}
3912
}

src/Node83.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// phpcs:ignoreFile
3+
namespace Gt\Dom;
4+
5+
use DOMNode;
6+
7+
class Node83 extends DOMNode {
8+
use NonDocumentTypeChildNode;
9+
use ChildNode;
10+
use ParentNode;
11+
use RegisteredNodeClass;
12+
13+
const TYPE_ELEMENT = XML_ELEMENT_NODE;
14+
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
15+
const TYPE_TEXT = XML_TEXT_NODE;
16+
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
17+
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
18+
const TYPE_ENTITY = XML_ENTITY_NODE;
19+
const TYPE_PI = XML_PI_NODE;
20+
const TYPE_COMMENT = XML_COMMENT_NODE;
21+
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
22+
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
23+
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
24+
const TYPE_NOTATION = XML_NOTATION_NODE;
25+
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
26+
const TYPE_DTD = XML_DTD_NODE;
27+
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
28+
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
29+
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
30+
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
31+
32+
public const DOCUMENT_POSITION_DISCONNECTED = 0b000001;
33+
public const DOCUMENT_POSITION_PRECEDING = 0b000010;
34+
public const DOCUMENT_POSITION_FOLLOWING = 0b000100;
35+
public const DOCUMENT_POSITION_CONTAINS = 0b001000;
36+
public const DOCUMENT_POSITION_CONTAINED_BY = 0b010000;
37+
public const DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0b100000;
38+
39+
private function __construct() {}
40+
}

src/Node84.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
// phpcs:ignoreFile
3+
namespace Gt\Dom;
4+
5+
use DOMNode;
6+
7+
class Node84 extends DOMNode {
8+
use NonDocumentTypeChildNode;
9+
use ChildNode;
10+
use ParentNode;
11+
use RegisteredNodeClass;
12+
13+
const TYPE_ELEMENT = XML_ELEMENT_NODE;
14+
const TYPE_ATTR = XML_ATTRIBUTE_NODE;
15+
const TYPE_TEXT = XML_TEXT_NODE;
16+
const TYPE_CDATA = XML_CDATA_SECTION_NODE;
17+
const TYPE_ENTITY_REF = XML_ENTITY_REF_NODE;
18+
const TYPE_ENTITY = XML_ENTITY_NODE;
19+
const TYPE_PI = XML_PI_NODE;
20+
const TYPE_COMMENT = XML_COMMENT_NODE;
21+
const TYPE_DOCUMENT = XML_DOCUMENT_NODE;
22+
const TYPE_DOCUMENT_TYPE = XML_DOCUMENT_TYPE_NODE;
23+
const TYPE_DOCUMENT_FRAGMENT = XML_DOCUMENT_FRAG_NODE;
24+
const TYPE_NOTATION = XML_NOTATION_NODE;
25+
const TYPE_HTML_DOCUMENT = XML_HTML_DOCUMENT_NODE;
26+
const TYPE_DTD = XML_DTD_NODE;
27+
const TYPE_ELEMENT_DECL = XML_ELEMENT_DECL_NODE;
28+
const TYPE_ATTRIBUTE_DECL = XML_ATTRIBUTE_DECL_NODE;
29+
const TYPE_ENTITY_DECL = XML_ENTITY_DECL_NODE;
30+
const TYPE_NAMESPACE_DECL = XML_NAMESPACE_DECL_NODE;
31+
32+
public const int DOCUMENT_POSITION_DISCONNECTED = 0b000001;
33+
public const int DOCUMENT_POSITION_PRECEDING = 0b000010;
34+
public const int DOCUMENT_POSITION_FOLLOWING = 0b000100;
35+
public const int DOCUMENT_POSITION_CONTAINS = 0b001000;
36+
public const int DOCUMENT_POSITION_CONTAINED_BY = 0b010000;
37+
public const int DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0b100000;
38+
39+
private function __construct() {}
40+
}

test/phpunit/NodeTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Gt\Dom\Test;
33

4-
use Gt\Dom\Exception\ClientSideOnlyFunctionalityException;
54
use Gt\Dom\Exception\NotFoundErrorException;
65
use Gt\Dom\HTMLDocument;
76
use Gt\Dom\Node;
@@ -13,7 +12,7 @@
1312
class NodeTest extends TestCase {
1413
public function testCanNotConstruct():void {
1514
self::expectException(\Error::class);
16-
self::expectExceptionMessage("Call to private Gt\Dom\Node::__construct()");
15+
self::expectExceptionMessageMatches("/Call to private Gt.Dom.Node[0-9]*::__construct()/");
1716
$className = Node::class;
1817
/** @phpstan-ignore-next-line */
1918
new $className();
@@ -22,7 +21,13 @@ public function testCanNotConstruct():void {
2221
public function testBaseURIClientSideOnly():void {
2322
$document = new XMLDocument();
2423
$sut = $document->createElement("example");
25-
self::assertNull($sut->baseURI);
24+
25+
if(version_compare(PHP_VERSION, "8.4", ">=")) {
26+
self::assertEquals(getcwd() . "/", $sut->baseURI);
27+
}
28+
else {
29+
self::assertNull($sut->baseURI);
30+
}
2631
}
2732

2833
public function testChildNodesEmpty():void {

test/phpunit/XMLDocumentTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ public function testBodyNullOnXML():void {
2424

2525
public function testToStringEmptyXML():void {
2626
$sut = new XMLDocument();
27-
self::assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xml/>\n", (string)$sut);
27+
if(version_compare(PHP_VERSION, "8.4", ">=")) {
28+
self::assertEquals("<?xml version=\"1.0\"?>\n<xml/>\n", (string)$sut);
29+
}
30+
else {
31+
self::assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<xml/>\n", (string)$sut);
32+
}
2833
}
2934

3035
public function testPropContentTypeEmpty():void {

0 commit comments

Comments
 (0)