From a2c79a556dbbc6aab1b896052009768f140aa629 Mon Sep 17 00:00:00 2001 From: picas Date: Thu, 15 Feb 2024 16:30:33 +0100 Subject: [PATCH] fix: arrayIterator + null string warnings * arrayIterator warning for the \MarkdownExtended\Util\ContentCollection object in PHP 8 * add a validation on an eventually null string --- composer.json | 2 +- src/MarkdownExtended/Util/ContentCollection.php | 2 ++ src/MarkdownExtended/Util/Helper.php | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index e6c2fd4..1f056e7 100644 --- a/composer.json +++ b/composer.json @@ -55,7 +55,7 @@ }, "scripts": { "doc": "phpdoc project:run --sourcecode --cache-folder=/tmp/phpdoc-cache/ --force -v", - "test": "php ./bin/phpunit --no-coverage --no-logging --testdox", + "test": "php ./bin/phpunit --no-coverage --no-logging --testdox --verbose", "test-coverage": "php ./bin/phpunit --debug", "metrics": "php ./bin/phpmetrics --config=.phpmetrics.yml src/", "dedup": "php ./bin/phpcpd --exclude=src/MarkdownExtendedDev/ src/", diff --git a/src/MarkdownExtended/Util/ContentCollection.php b/src/MarkdownExtended/Util/ContentCollection.php index f019fa1..34f977e 100644 --- a/src/MarkdownExtended/Util/ContentCollection.php +++ b/src/MarkdownExtended/Util/ContentCollection.php @@ -38,6 +38,7 @@ public function __construct(array $data = []) * * @throws \MarkdownExtended\Exception\UnexpectedValueException it the argument does not implement `\MarkdownExtended\API\ContentInterface` */ + #[\ReturnTypeWillChange] public function append($content) { if (!is_object($content) || !Kernel::valid($content, Kernel::TYPE_CONTENT)) { @@ -61,6 +62,7 @@ public function append($content) * * @throws \MarkdownExtended\Exception\UnexpectedValueException it the argument does not implement `\MarkdownExtended\API\ContentInterface` */ + #[\ReturnTypeWillChange] public function offsetSet($index, $content) { if (!is_object($content) || !Kernel::valid($content, Kernel::TYPE_CONTENT)) { diff --git a/src/MarkdownExtended/Util/Helper.php b/src/MarkdownExtended/Util/Helper.php index a9e3f3b..05b6f54 100644 --- a/src/MarkdownExtended/Util/Helper.php +++ b/src/MarkdownExtended/Util/Helper.php @@ -42,7 +42,7 @@ public static function escapeCodeContent($code) */ public static function fillPlaceholders($text, $replacement) { - return str_replace('%%', $replacement, $text); + return !is_null($text) ? str_replace('%%', $replacement, $text) : $text; } /**