Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix PHPStan issues and build on PHP 8.2 #368

Merged
merged 11 commits into from Sep 5, 2022
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php:
php:
- '7.4'
- '8.0'
- '8.1'
Expand All @@ -26,4 +26,5 @@ jobs:
- run: composer install --no-progress
# - run: composer codestyle
- run: composer phpstan
if: matrix.php == '8.1'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we run PHPStan on every version, we'll use different versions of PHPStan detecting different sets of issues (due to bugs in older versions or whatnot).

- run: composer tests
1 change: 1 addition & 0 deletions Michelf/MarkdownExtra.php
Expand Up @@ -601,6 +601,7 @@ protected function _hashHTMLBlocks_inMarkdown($text, $indent = 0,
else {
$parsed .= $tag;
}
// @phpstan-ignore-next-line
} while ($depth >= 0);

return array($parsed, $text);
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Expand Up @@ -24,11 +24,10 @@
"psr-4": { "Michelf\\": "Michelf/" }
},
"require-dev": {
"phpspec/prophecy": "^1.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for this dependency. See:
sebastianbergmann/phpunit#5033 (comment)

"friendsofphp/php-cs-fixer": "^3.0",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-phpunit": "^1.0"
"phpstan/phpstan": ">=1.0",
"phpstan/phpstan-phpunit": ">=1.0"
},

"scripts": {
Expand Down
11 changes: 6 additions & 5 deletions test/helpers/MarkdownTestHelper.php
Expand Up @@ -22,7 +22,6 @@ public static function getInputOutputPaths($directory) {

$dataValues = array();

/** @var SplFileInfo $inputFile */
foreach ($regexIterator as $inputFiles) {
foreach ($inputFiles as $inputMarkdownPath) {
$xhtml = true;
Expand Down Expand Up @@ -163,6 +162,7 @@ protected static function normalizeElementContent($element, $whitespace_preserve
foreach ($node_list as $node) {
switch ($node->nodeType) {
case XML_ELEMENT_NODE:
/** @var DOMElement $node */
static::normalizeElementContent($node, $whitespace_preserve);
static::normalizeElementAttributes($node);

Expand Down Expand Up @@ -207,6 +207,7 @@ protected static function normalizeElementContent($element, $whitespace_preserve
break;

case XML_TEXT_NODE:
/** @var DOMText $node */
if (!$whitespace_preserve) {
if (trim($node->data) === "") {
$node->data = $whitespace;
Expand All @@ -222,17 +223,17 @@ protected static function normalizeElementContent($element, $whitespace_preserve
($whitespace === "\n\n" || $whitespace === "\n")) {
if ($element->firstChild) {
if ($element->firstChild->nodeType == XML_TEXT_NODE) {
$element->firstChild->data =
preg_replace('{^\s+}', "\n", $element->firstChild->data);
$element->firstChild->data = // @phpstan-ignore-line
preg_replace('{^\s+}', "\n", $element->firstChild->data ?? '');
}
else {
$element->insertBefore(new DOMText("\n"), $element->firstChild);
}
}
if ($element->lastChild) {
if ($element->lastChild->nodeType == XML_TEXT_NODE) {
$element->lastChild->data =
preg_replace('{\s+$}', "\n", $element->lastChild->data);
$element->lastChild->data = // @phpstan-ignore-line
preg_replace('{\s+$}', "\n", $element->lastChild->data ?? '');
}
else {
$element->insertBefore(new DOMText("\n"), null);
Expand Down