Fix PHPStan issues and build on PHP 8.2 (#368)

Limit PHPStan to PHP 8.1
This commit is contained in:
Alexey Kopytko 2022-09-05 10:33:36 +09:00 committed by GitHub
parent 6ca731e849
commit 546b80a136
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 9 deletions

View file

@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
matrix: matrix:
php: php:
- '7.4' - '7.4'
- '8.0' - '8.0'
- '8.1' - '8.1'
@ -26,4 +26,5 @@ jobs:
- run: composer install --no-progress - run: composer install --no-progress
# - run: composer codestyle # - run: composer codestyle
- run: composer phpstan - run: composer phpstan
if: matrix.php == '8.1'
- run: composer tests - run: composer tests

View file

@ -601,6 +601,7 @@ class MarkdownExtra extends \Michelf\Markdown {
else { else {
$parsed .= $tag; $parsed .= $tag;
} }
// @phpstan-ignore-next-line
} while ($depth >= 0); } while ($depth >= 0);
return array($parsed, $text); return array($parsed, $text);

View file

@ -24,11 +24,10 @@
"psr-4": { "Michelf\\": "Michelf/" } "psr-4": { "Michelf\\": "Michelf/" }
}, },
"require-dev": { "require-dev": {
"phpspec/prophecy": "^1.6",
"friendsofphp/php-cs-fixer": "^3.0", "friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.5", "phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.0", "phpstan/phpstan": ">=1.0",
"phpstan/phpstan-phpunit": "^1.0" "phpstan/phpstan-phpunit": ">=1.0"
}, },
"scripts": { "scripts": {

View file

@ -22,7 +22,6 @@ class MarkdownTestHelper
$dataValues = array(); $dataValues = array();
/** @var SplFileInfo $inputFile */
foreach ($regexIterator as $inputFiles) { foreach ($regexIterator as $inputFiles) {
foreach ($inputFiles as $inputMarkdownPath) { foreach ($inputFiles as $inputMarkdownPath) {
$xhtml = true; $xhtml = true;
@ -163,6 +162,7 @@ class MarkdownTestHelper
foreach ($node_list as $node) { foreach ($node_list as $node) {
switch ($node->nodeType) { switch ($node->nodeType) {
case XML_ELEMENT_NODE: case XML_ELEMENT_NODE:
/** @var DOMElement $node */
static::normalizeElementContent($node, $whitespace_preserve); static::normalizeElementContent($node, $whitespace_preserve);
static::normalizeElementAttributes($node); static::normalizeElementAttributes($node);
@ -207,6 +207,7 @@ class MarkdownTestHelper
break; break;
case XML_TEXT_NODE: case XML_TEXT_NODE:
/** @var DOMText $node */
if (!$whitespace_preserve) { if (!$whitespace_preserve) {
if (trim($node->data) === "") { if (trim($node->data) === "") {
$node->data = $whitespace; $node->data = $whitespace;
@ -222,8 +223,8 @@ class MarkdownTestHelper
($whitespace === "\n\n" || $whitespace === "\n")) { ($whitespace === "\n\n" || $whitespace === "\n")) {
if ($element->firstChild) { if ($element->firstChild) {
if ($element->firstChild->nodeType == XML_TEXT_NODE) { if ($element->firstChild->nodeType == XML_TEXT_NODE) {
$element->firstChild->data = $element->firstChild->data = // @phpstan-ignore-line
preg_replace('{^\s+}', "\n", $element->firstChild->data); preg_replace('{^\s+}', "\n", $element->firstChild->data ?? '');
} }
else { else {
$element->insertBefore(new DOMText("\n"), $element->firstChild); $element->insertBefore(new DOMText("\n"), $element->firstChild);
@ -231,8 +232,8 @@ class MarkdownTestHelper
} }
if ($element->lastChild) { if ($element->lastChild) {
if ($element->lastChild->nodeType == XML_TEXT_NODE) { if ($element->lastChild->nodeType == XML_TEXT_NODE) {
$element->lastChild->data = $element->lastChild->data = // @phpstan-ignore-line
preg_replace('{\s+$}', "\n", $element->lastChild->data); preg_replace('{\s+$}', "\n", $element->lastChild->data ?? '');
} }
else { else {
$element->insertBefore(new DOMText("\n"), null); $element->insertBefore(new DOMText("\n"), null);