Skip to content

Commit 7f99a26

Browse files
authored
Merge pull request #26 from GravityPDF/php-8.2-testing
PHP 8.2 Support
2 parents aee3c64 + c47a80c commit 7f99a26

8 files changed

Lines changed: 38 additions & 39 deletions

File tree

.github/workflows/unit-testing.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1' ]
10+
php-versions: [ '7.1', '7.2', '7.3', '7.4', '8.0', '8.1', '8.2' ]
1111
name: PHP ${{ matrix.php-versions }} PHPUnit Test
1212
steps:
1313
- name: Checkout repository

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
}
2424
],
2525
"require": {
26-
"php": "^7.1 || ~8.0.0 || ~8.1.0",
26+
"php": "^7.1 || ~8.0.0 || ~8.1.0 || ~8.2.0",
2727
"masterminds/html5": "^2.0"
2828
},
2929
"autoload": {

src/CSS/InputStream.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ class InputStream
2020
/**
2121
* Build a new CSS input stream from a string.
2222
*
23-
* @param string
24-
* String to turn into an input stream.
23+
* @param string $string String to turn into an input stream.
24+
*
25+
* @internal PHP8.2 changed how str_split() processes empty strings, so the empty() check maintains the pre8.2 status quo
2526
*/
2627
public function __construct($string)
2728
{
28-
$this->stream = str_split($string);
29+
$this->stream = !empty($string) ? str_split($string) : [''];
2930
}
3031

3132
/**

src/CSS/Parser.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
*/
2626
class Parser
2727
{
28+
/**
29+
* @var string
30+
*/
31+
protected $originalString;
32+
2833
protected $scanner;
2934
protected $buffer = '';
3035
protected $handler;

src/CSS/QueryPathEventHandler.php

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -761,44 +761,41 @@ protected function nthChild($groupSize, $elementInGroup, $lastChild = false)
761761
// though.
762762
$parents = new SplObjectStorage();
763763
$matches = new SplObjectStorage();
764+
$index = new SplObjectStorage();
764765

765-
$i = 0;
766766
foreach ($this->matches as $item) {
767767
$parent = $item->parentNode;
768768

769769
// Build up an array of all of children of this parent, and store the
770770
// index of each element for reference later. We only need to do this
771771
// once per parent, though.
772-
if (! $parents->contains($parent)) {
772+
if (!$parents->contains($parent)) {
773773
$c = 0;
774774
foreach ($parent->childNodes as $child) {
775775
// We only want nodes, and if this call is preceded by an element
776776
// selector, we only want to match elements with the same tag name.
777777
// !!! This last part is a grey area in the CSS 3 Selector spec. It seems
778778
// necessary to make the implementation match the examples in the spec. However,
779779
// jQuery 1.2 does not do this.
780-
if ($child->nodeType == XML_ELEMENT_NODE && ($this->findAnyElement || $child->tagName == $item->tagName)) {
781-
// This may break E_STRICT.
782-
$child->nodeIndex = ++$c;
780+
if ($child->nodeType === XML_ELEMENT_NODE && ($this->findAnyElement || $child->tagName === $item->tagName)) {
781+
$index->attach($child, ++$c);
783782
}
784783
}
785-
// This may break E_STRICT.
786-
$parent->numElements = $c;
787-
$parents->attach($parent);
784+
$parents->attach($parent, $c);
788785
}
789786

790787
// If we are looking for the last child, we count from the end of a list.
791788
// Note that we add 1 because CSS indices begin at 1, not 0.
792789
if ($lastChild) {
793-
$indexToMatch = $item->parentNode->numElements - $item->nodeIndex + 1;
790+
$indexToMatch = $parents->offsetGet($item->parentNode) - $index->offsetGet($item) + 1;
794791
} // Otherwise we count from the beginning of the list.
795792
else {
796-
$indexToMatch = $item->nodeIndex;
793+
$indexToMatch = $index->offsetGet($item);
797794
}
798795

799796
// If group size is 0, then we return element at the right index.
800-
if ($groupSize == 0) {
801-
if ($indexToMatch == $elementInGroup) {
797+
if ($groupSize === 0) {
798+
if ($indexToMatch === $elementInGroup) {
802799
$matches->attach($item);
803800
}
804801
}
@@ -810,9 +807,6 @@ protected function nthChild($groupSize, $elementInGroup, $lastChild = false)
810807
$matches->attach($item);
811808
}
812809
}
813-
814-
// Iterate.
815-
++$i;
816810
}
817811
$this->matches = $matches;
818812
}
@@ -950,45 +944,42 @@ protected function childAtIndex($index, $tagName = NULL) {
950944
protected function nthOfTypeChild($groupSize, $elementInGroup, $lastChild)
951945
{
952946
// EXPERIMENTAL: New in Quark. This should be substantially faster
953-
// than the old (jQuery-ish) version. It still has E_STRICT violations
954-
// though.
947+
// than the old (jQuery-ish) version.
955948
$parents = new SplObjectStorage();
956949
$matches = new SplObjectStorage();
950+
$index = new SplObjectStorage();
957951

958-
$i = 0;
959952
foreach ($this->matches as $item) {
960953
$parent = $item->parentNode;
961954

962955
// Build up an array of all of children of this parent, and store the
963956
// index of each element for reference later. We only need to do this
964957
// once per parent, though.
965-
if (! $parents->contains($parent)) {
958+
if (!$parents->contains($parent)) {
966959
$c = 0;
967960
foreach ($parent->childNodes as $child) {
968961
// This doesn't totally make sense, since the CSS 3 spec does not require that
969962
// this pseudo-class be adjoined to an element (e.g. ' :nth-of-type' is allowed).
970-
if ($child->nodeType == XML_ELEMENT_NODE && $child->tagName == $item->tagName) {
971-
// This may break E_STRICT.
972-
$child->nodeIndex = ++$c;
963+
if ($child->nodeType === XML_ELEMENT_NODE && $child->tagName === $item->tagName) {
964+
$index->attach($child, ++$c);
973965
}
974966
}
975-
// This may break E_STRICT.
976-
$parent->numElements = $c;
977-
$parents->attach($parent);
967+
968+
$parents->attach($parent, $c);
978969
}
979970

980971
// If we are looking for the last child, we count from the end of a list.
981972
// Note that we add 1 because CSS indices begin at 1, not 0.
982973
if ($lastChild) {
983-
$indexToMatch = $item->parentNode->numElements - $item->nodeIndex + 1;
974+
$indexToMatch = $parents->offsetGet($item->parentNode) - $index->offsetGet($item) + 1;
984975
} // Otherwise we count from the beginning of the list.
985976
else {
986-
$indexToMatch = $item->nodeIndex;
977+
$indexToMatch = $index->offsetGet($item);
987978
}
988979

989980
// If group size is 0, then we return element at the right index.
990-
if ($groupSize == 0) {
991-
if ($indexToMatch == $elementInGroup) {
981+
if ($groupSize === 0) {
982+
if ($indexToMatch === $elementInGroup) {
992983
$matches->attach($item);
993984
}
994985
}
@@ -1000,9 +991,6 @@ protected function nthOfTypeChild($groupSize, $elementInGroup, $lastChild)
1000991
$matches->attach($item);
1001992
}
1002993
}
1003-
1004-
// Iterate.
1005-
++$i;
1006994
}
1007995
$this->matches = $matches;
1008996
}

tests/QueryPath/ExtensionTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @ingroup querypath_tests
1414
* @group extension
1515
*/
16-
class QueryPathExtensionTest extends TestCase
16+
class ExtensionTest extends TestCase
1717
{
1818

1919
public static function set_up_before_class()

tests/QueryPath/QueryPathTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ public function testEnable()
5050
class DummyExtension implements Extension
5151
{
5252

53+
/**
54+
* @var Query
55+
*/
56+
protected $qp;
57+
5358
public function __construct(Query $qp)
5459
{
5560
$this->qp = $qp;

tests/QueryPath/XMLIshTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
* @ingroup querypath_test
1414
*/
15-
class XMLishTest extends TestCase
15+
class XMLIshTest extends TestCase
1616
{
1717

1818
public function testXMLishMock()

0 commit comments

Comments
 (0)