Skip to content

Commit 397aa8b

Browse files
committed
Adds compatibility with PHP 8.0 | 8.1. Fix some PHPStan warnings.
1 parent 6effff7 commit 397aa8b

File tree

5 files changed

+26
-22
lines changed

5 files changed

+26
-22
lines changed

.github/workflows/main.yaml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,17 @@ jobs:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
matrix:
14-
php: ['7.1', '7.2', '7.3', '7.4']
14+
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
1515
name: PHP ${{ matrix.php }} tests
1616
steps:
1717
- uses: actions/checkout@v2
1818
# required for "git tag" presence for MonorepoBuilder split and ChangelogLinker git tags resolver; default is 1
1919
- run: git fetch --depth=100000 origin
2020
# see https://github.com/shivammathur/setup-php
21-
- uses: shivammathur/setup-php@v1
21+
- uses: shivammathur/setup-php@v2
2222
with:
2323
php-version: ${{ matrix.php }}
24+
extensions: xml
2425
coverage: none
2526
- run: composer install --no-progress
2627
- run: composer phpunit
@@ -31,9 +32,10 @@ jobs:
3132
- uses: actions/checkout@v2
3233
- run: git fetch --depth=100000 origin
3334
# see https://github.com/shivammathur/setup-php
34-
- uses: shivammathur/setup-php@v1
35+
- uses: shivammathur/setup-php@v2
3536
with:
3637
php-version: 7.1
38+
extensions: xml
3739
coverage: none
3840
- run: composer update --no-progress --prefer-lowest
3941
- run: composer phpunit
@@ -44,9 +46,10 @@ jobs:
4446
- uses: actions/checkout@v2
4547
- run: git fetch --depth=100000 origin
4648
# see https://github.com/shivammathur/setup-php
47-
- uses: shivammathur/setup-php@v1
49+
- uses: shivammathur/setup-php@v2
4850
with:
4951
php-version: 7.1
52+
extensions: xml, xdebug
5053
coverage: xdebug
5154
- run: composer install --no-progress
5255
- run : |
@@ -61,9 +64,10 @@ jobs:
6164
steps:
6265
- uses: actions/checkout@v2
6366
# see https://github.com/shivammathur/setup-php
64-
- uses: shivammathur/setup-php@v1
67+
- uses: shivammathur/setup-php@v2
6568
with:
6669
php-version: 7.4
70+
extensions: xml
6771
coverage: none
6872
- run: composer install --no-progress
6973
- run: composer php-cs-fixer-dry-run
@@ -72,9 +76,9 @@ jobs:
7276
runs-on: ubuntu-latest
7377
steps:
7478
- uses: actions/checkout@v2
75-
- uses: shivammathur/setup-php@v1
79+
- uses: shivammathur/setup-php@v2
7680
with:
77-
php-version: 7.4
81+
php-version: 7.1
7882
coverage: none
7983
- run: composer install --no-progress
8084
- run: composer phpstan

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
}
1717
],
1818
"require": {
19-
"php": "^7.1",
19+
"php": "^7.1 || ^8.0",
2020
"ext-dom": "*",
2121
"ext-filter": "*",
2222
"ext-libxml": "*",
@@ -25,9 +25,9 @@
2525
},
2626
"require-dev": {
2727
"friendsofphp/php-cs-fixer": "^3.0",
28-
"phpstan/phpstan": "^0.12.26",
29-
"phpstan/phpstan-strict-rules": "^0.12",
30-
"phpstan/phpstan-webmozart-assert": "^0.12",
28+
"phpstan/phpstan": "^1.0",
29+
"phpstan/phpstan-strict-rules": "^1.0",
30+
"phpstan/phpstan-webmozart-assert": "^1.0",
3131
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
3232
},
3333
"config": {

src/AbstractElement.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use DateTime;
66
use DateTimeInterface;
7-
use DOMElement;
87
use InvalidArgumentException;
98
use SimpleXMLElement;
109
use Webmozart\Assert\Assert;
@@ -38,7 +37,7 @@ abstract class AbstractElement
3837
/** @var string[][] */
3938
protected $categories = [];
4039

41-
/** @var mixed[][] */
40+
/** @var string[][] */
4241
protected $links = [];
4342

4443
/**
@@ -123,7 +122,7 @@ public function addLink(string $uri, ?string $rel = null, ?string $type = null,
123122
}
124123

125124
if (null !== $length) {
126-
$link['length'] = $length;
125+
$link['length'] = (string) $length;
127126
}
128127

129128
$this->links[] = $link;
@@ -177,7 +176,7 @@ public function addChildrenTo(SimpleXMLElement $parent): void
177176
}
178177

179178
/**
180-
* @return mixed[]
179+
* @return string[]
181180
*/
182181
protected static function createPerson(string $name, ?string $email = null, ?string $uri = null): array
183182
{
@@ -220,7 +219,7 @@ protected static function addChildWithTypeToElement(SimpleXMLElement $parent, st
220219
protected static function addCData(string $cdataText, SimpleXMLElement $element): void
221220
{
222221
$node = dom_import_simplexml($element);
223-
Assert::isInstanceOf($node, DOMElement::class);
222+
assert(false !== $node);
224223
$no = $node->ownerDocument;
225224
assert(null !== $no);
226225
$node->appendChild($no->createCDATASection($cdataText));

src/Feed.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace AtomGenerator;
44

55
use DOMDocument;
6-
use DOMElement;
76
use LibXMLError;
87
use SimpleXMLElement;
98
use Webmozart\Assert\Assert;
@@ -37,7 +36,10 @@ class Feed extends AbstractElement
3736
/** @var null|string */
3837
protected $generatorUri;
3938

40-
/** @var mixed[][] */
39+
/**
40+
* @var mixed[][]
41+
* @phpstan-var array<array{ns: string, uri: string, name: string, value: string, attributes: string[]}>
42+
*/
4143
protected $customElements = [];
4244

4345
/**
@@ -114,10 +116,9 @@ public function getEntries(): array
114116
}
115117

116118
/**
117-
* @param mixed $value
118119
* @param null|string[] $attributes
119120
*/
120-
public function addCustomElement(string $ns, string $uri, string $name, $value, ?array $attributes = null): void
121+
public function addCustomElement(string $ns, string $uri, string $name, string $value, ?array $attributes = null): void
121122
{
122123
self::assertURL($uri);
123124

@@ -193,7 +194,7 @@ public function getSimpleXML(): SimpleXMLElement
193194
public function getDocument(): DOMDocument
194195
{
195196
$node = dom_import_simplexml($this->getSimpleXML());
196-
Assert::isInstanceOf($node, DOMElement::class);
197+
assert(false !== $node);
197198
$no = $node->ownerDocument;
198199
assert(null !== $no);
199200

tests/FeedTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function testFeedCreation1(): void
4040
$feed->addContributor('contributor', 'contributor@test.com', 'http://test.com/contributor?a=b&c=d');
4141
$feed->setUpdatedDateTime(new DateTime('2019-05-04T20:00:40Z'));
4242
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updatePeriod', 'hourly');
43-
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updateFrequency', 10);
43+
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updateFrequency', '10');
4444

4545
$entry = new Entry();
4646
$entry->setTitle('entry title', 'text');

0 commit comments

Comments
 (0)