Skip to content

Commit

Permalink
Adds compatibility with PHP 8.0 | 8.1. Fix some PHPStan warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebin committed Jan 6, 2022
1 parent 6effff7 commit 397aa8b
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.1', '7.2', '7.3', '7.4']
php: ['7.1', '7.2', '7.3', '7.4', '8.0', '8.1']
name: PHP ${{ matrix.php }} tests
steps:
- uses: actions/checkout@v2
# required for "git tag" presence for MonorepoBuilder split and ChangelogLinker git tags resolver; default is 1
- run: git fetch --depth=100000 origin
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: xml
coverage: none
- run: composer install --no-progress
- run: composer phpunit
Expand All @@ -31,9 +32,10 @@ jobs:
- uses: actions/checkout@v2
- run: git fetch --depth=100000 origin
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@v2
with:
php-version: 7.1
extensions: xml
coverage: none
- run: composer update --no-progress --prefer-lowest
- run: composer phpunit
Expand All @@ -44,9 +46,10 @@ jobs:
- uses: actions/checkout@v2
- run: git fetch --depth=100000 origin
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@v2
with:
php-version: 7.1
extensions: xml, xdebug
coverage: xdebug
- run: composer install --no-progress
- run : |
Expand All @@ -61,9 +64,10 @@ jobs:
steps:
- uses: actions/checkout@v2
# see https://github.com/shivammathur/setup-php
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
extensions: xml
coverage: none
- run: composer install --no-progress
- run: composer php-cs-fixer-dry-run
Expand All @@ -72,9 +76,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: shivammathur/setup-php@v1
- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 7.1
coverage: none
- run: composer install --no-progress
- run: composer phpstan
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
],
"require": {
"php": "^7.1",
"php": "^7.1 || ^8.0",
"ext-dom": "*",
"ext-filter": "*",
"ext-libxml": "*",
Expand All @@ -25,9 +25,9 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"phpstan/phpstan": "^0.12.26",
"phpstan/phpstan-strict-rules": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-strict-rules": "^1.0",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0"
},
"config": {
Expand Down
9 changes: 4 additions & 5 deletions src/AbstractElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use DateTime;
use DateTimeInterface;
use DOMElement;
use InvalidArgumentException;
use SimpleXMLElement;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -38,7 +37,7 @@ abstract class AbstractElement
/** @var string[][] */
protected $categories = [];

/** @var mixed[][] */
/** @var string[][] */
protected $links = [];

/**
Expand Down Expand Up @@ -123,7 +122,7 @@ public function addLink(string $uri, ?string $rel = null, ?string $type = null,
}

if (null !== $length) {
$link['length'] = $length;
$link['length'] = (string) $length;
}

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

/**
* @return mixed[]
* @return string[]
*/
protected static function createPerson(string $name, ?string $email = null, ?string $uri = null): array
{
Expand Down Expand Up @@ -220,7 +219,7 @@ protected static function addChildWithTypeToElement(SimpleXMLElement $parent, st
protected static function addCData(string $cdataText, SimpleXMLElement $element): void
{
$node = dom_import_simplexml($element);
Assert::isInstanceOf($node, DOMElement::class);
assert(false !== $node);
$no = $node->ownerDocument;
assert(null !== $no);
$node->appendChild($no->createCDATASection($cdataText));
Expand Down
11 changes: 6 additions & 5 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace AtomGenerator;

use DOMDocument;
use DOMElement;
use LibXMLError;
use SimpleXMLElement;
use Webmozart\Assert\Assert;
Expand Down Expand Up @@ -37,7 +36,10 @@ class Feed extends AbstractElement
/** @var null|string */
protected $generatorUri;

/** @var mixed[][] */
/**
* @var mixed[][]
* @phpstan-var array<array{ns: string, uri: string, name: string, value: string, attributes: string[]}>
*/
protected $customElements = [];

/**
Expand Down Expand Up @@ -114,10 +116,9 @@ public function getEntries(): array
}

/**
* @param mixed $value
* @param null|string[] $attributes
*/
public function addCustomElement(string $ns, string $uri, string $name, $value, ?array $attributes = null): void
public function addCustomElement(string $ns, string $uri, string $name, string $value, ?array $attributes = null): void
{
self::assertURL($uri);

Expand Down Expand Up @@ -193,7 +194,7 @@ public function getSimpleXML(): SimpleXMLElement
public function getDocument(): DOMDocument
{
$node = dom_import_simplexml($this->getSimpleXML());
Assert::isInstanceOf($node, DOMElement::class);
assert(false !== $node);
$no = $node->ownerDocument;
assert(null !== $no);

Expand Down
2 changes: 1 addition & 1 deletion tests/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFeedCreation1(): void
$feed->addContributor('contributor', '[email protected]', 'http://test.com/contributor?a=b&c=d');
$feed->setUpdatedDateTime(new DateTime('2019-05-04T20:00:40Z'));
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updatePeriod', 'hourly');
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updateFrequency', 10);
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updateFrequency', '10');

$entry = new Entry();
$entry->setTitle('entry title', 'text');
Expand Down

0 comments on commit 397aa8b

Please sign in to comment.