Skip to content

Commit 934a2a9

Browse files
authored
Add PHP 8-only Support (v3) (#162)
* require PHP 8+, PHPUnit 9.5+ * drop PHP 7.x support * update/add dot files from spatie/package-skeleton-php * update phpunit config * use PHP 8 syntax, add typehints, drop unneeded docblocks * update changelog * update readme with minor adjustments from skeleton
1 parent 3784621 commit 934a2a9

10 files changed

+95
-47
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
indent_style = space
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.{yml,yaml}]
15+
indent_size = 2

.gitattributes

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
21
# Path-based git attributes
32
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
43

54
# Ignore all test and documentation with "export-ignore".
65
/.gitattributes export-ignore
76
/.gitignore export-ignore
8-
/.travis.yml export-ignore
97
/phpunit.xml.dist export-ignore
10-
/.scrutinizer.yml export-ignore
11-
/tests export-ignore
8+
/tests export-ignore
9+
/.editorconfig export-ignore
10+
/.php_cs export-ignore
11+
/.github export-ignore
12+
/psalm.xml export-ignore
13+

.github/workflows/run-tests.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest]
12-
php: [8.0, 7.4]
12+
php: [8.0]
1313
stability: [prefer-lowest, prefer-stable]
1414

1515
name: P${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}
@@ -24,7 +24,7 @@ jobs:
2424
php-version: ${{ matrix.php }}
2525
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
2626
coverage: none
27-
27+
2828
- name: Setup problem matchers
2929
run: |
3030
echo "::add-matcher::${{ runner.tool_cache }}/php.json"

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
.idea
2+
.php_cs
3+
.php_cs.cache
4+
.phpunit.result.cache
15
build
26
composer.lock
7+
coverage
38
docs
9+
phpunit.xml
10+
psalm.xml
411
vendor
5-
.php_cs.cache

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
All notable changes to `array-to-xml` will be documented in this file
44

5+
## 3.0.0 - unreleased
6+
7+
- require PHP 8+
8+
- drop support for PHP 7.x
9+
- convert syntax to PHP 8
10+
511
## 2.16.0 - 2020-11-18
612

713
- add escapable colons in custom keys (#151)

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -483,17 +483,17 @@ This will result in:
483483
vendor/bin/phpunit
484484
```
485485

486-
### Changelog
486+
## Changelog
487487

488-
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
488+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
489489

490490
## Contributing
491491

492-
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
492+
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
493493

494-
## Security
494+
## Security Vulnerabilities
495495

496-
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
496+
Please review [our security policy](../../security/policy) on how to report security vulnerabilities.
497497

498498
## Postcardware
499499

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
}
1818
],
1919
"require": {
20-
"php" : "^7.4|^8.0",
20+
"php" : "^8.0",
2121
"ext-dom": "*"
2222
},
2323
"require-dev": {
24-
"phpunit/phpunit" : "^9.0",
24+
"phpunit/phpunit" : "^9.5",
2525
"mockery/mockery": "^1.2",
2626
"spatie/phpunit-snapshot-assertions": "^4.2"
2727
},

phpunit.xml

-13
This file was deleted.

phpunit.xml.dist

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
bootstrap="vendor/autoload.php"
8+
colors="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false"
14+
executionOrder="random"
15+
failOnWarning="true"
16+
failOnRisky="true"
17+
failOnEmptyTestSuite="true"
18+
beStrictAboutOutputDuringTests="true"
19+
verbose="true"
20+
>
21+
<testsuites>
22+
<testsuite name="Spatie Test Suite">
23+
<directory>tests</directory>
24+
</testsuite>
25+
</testsuites>
26+
<coverage>
27+
<include>
28+
<directory suffix=".php">./src</directory>
29+
</include>
30+
<report>
31+
<html outputDirectory="build/coverage"/>
32+
<text outputFile="build/coverage.txt"/>
33+
<clover outputFile="build/logs/clover.xml"/>
34+
</report>
35+
</coverage>
36+
<logging>
37+
<junit outputFile="build/report.junit.xml"/>
38+
</logging>
39+
</phpunit>

src/ArrayToXml.php

+13-20
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,22 @@
99

1010
class ArrayToXml
1111
{
12-
protected $document;
12+
protected DOMDocument $document;
1313

14-
protected $replaceSpacesByUnderScoresInKeyNames = true;
14+
protected bool $replaceSpacesByUnderScoresInKeyNames = true;
1515

16-
protected $addXmlDeclaration = true;
16+
protected bool $addXmlDeclaration = true;
1717

18-
protected $numericTagNamePrefix = 'numeric_';
18+
protected string $numericTagNamePrefix = 'numeric_';
1919

20-
/**
21-
* @param mixed[] $array
22-
*/
2320
public function __construct(
2421
array $array,
25-
$rootElement = '',
26-
$replaceSpacesByUnderScoresInKeyNames = true,
27-
$xmlEncoding = null,
28-
$xmlVersion = '1.0',
29-
$domProperties = [],
30-
$xmlStandalone = null
22+
string | array $rootElement = '',
23+
bool $replaceSpacesByUnderScoresInKeyNames = true,
24+
?string $xmlEncoding = null,
25+
string $xmlVersion = '1.0',
26+
array $domProperties = [],
27+
?bool $xmlStandalone = null
3128
) {
3229
$this->document = new DOMDocument($xmlVersion, $xmlEncoding);
3330

@@ -57,9 +54,6 @@ public function setNumericTagNamePrefix(string $prefix): void
5754
$this->numericTagNamePrefix = $prefix;
5855
}
5956

60-
/**
61-
* @param mixed[] $array
62-
*/
6357
public static function convert(
6458
array $array,
6559
$rootElement = '',
@@ -162,7 +156,7 @@ private function convertElement(DOMElement $element, $value): void
162156
$element->appendChild($fragment);
163157
} elseif ($key === '__numeric') {
164158
$this->addNumericNode($element, $data);
165-
} elseif (substr($key, 0, 9) === '__custom:') {
159+
} elseif (str_starts_with($key, '__custom:')) {
166160
$this->addNode($element, str_replace('\:', ':', preg_split('/(?<!\\\):/', $key)[1]), $data);
167161
} else {
168162
$this->addNode($element, $key, $data);
@@ -206,7 +200,7 @@ protected function addCollectionNode(DOMElement $element, $value): void
206200
$this->convertElement($child, $value);
207201
}
208202

209-
protected function addSequentialNode(DOMElement $element, $value)
203+
protected function addSequentialNode(DOMElement $element, $value): void
210204
{
211205
if (empty($element->nodeValue) && ! is_numeric($element->nodeValue)) {
212206
$element->nodeValue = htmlspecialchars($value);
@@ -220,10 +214,9 @@ protected function addSequentialNode(DOMElement $element, $value)
220214
}
221215

222216
/**
223-
* @param mixed[] $value
224217
* @return bool|mixed[]
225218
*/
226-
protected function isArrayAllKeySequential($value)
219+
protected function isArrayAllKeySequential(array | string $value): mixed
227220
{
228221
if (! is_array($value)) {
229222
return false;

0 commit comments

Comments
 (0)