From 9f81424b4909007483d93c5defc0917d8a58debd Mon Sep 17 00:00:00 2001 From: Tomasz Kowalczyk Date: Sun, 15 Dec 2024 22:30:37 +0100 Subject: [PATCH] - detect deprecations in PHPUnit, - fixed all instances of PHP 8.4 deprecated implicitly marking parameters as nullable. --- phpunit.xml.dist | 10 +++++----- src/Event/FilterShortcodesEvent.php | 11 +++++++++-- src/Event/ReplaceShortcodesEvent.php | 7 ++++++- src/Parser/RegexParser.php | 7 ++++++- src/Parser/RegularParser.php | 7 ++++++- src/Processor/Processor.php | 6 +++++- src/Serializer/TextSerializer.php | 7 ++++++- 7 files changed, 43 insertions(+), 12 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 6620361..58203e2 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,10 @@ diff --git a/src/Event/FilterShortcodesEvent.php b/src/Event/FilterShortcodesEvent.php index dc554e3..072f257 100644 --- a/src/Event/FilterShortcodesEvent.php +++ b/src/Event/FilterShortcodesEvent.php @@ -18,9 +18,16 @@ class FilterShortcodesEvent /** @var ParsedShortcodeInterface[] */ private $shortcodes = array(); - /** @param ParsedShortcodeInterface[] $shortcodes */ - public function __construct(array $shortcodes, ProcessedShortcode $parent = null) + /** + * @param ParsedShortcodeInterface[] $shortcodes + * @param ProcessedShortcode|null $parent + */ + public function __construct(array $shortcodes, $parent = null) { + if(null !== $parent && false === $parent instanceof ProcessedShortcode) { + throw new \LogicException('Parameter $parent must be an instance of ProcessedShortcode.'); + } + $this->parent = $parent; $this->setShortcodes($shortcodes); } diff --git a/src/Event/ReplaceShortcodesEvent.php b/src/Event/ReplaceShortcodesEvent.php index 39e1827..50218f6 100644 --- a/src/Event/ReplaceShortcodesEvent.php +++ b/src/Event/ReplaceShortcodesEvent.php @@ -25,9 +25,14 @@ class ReplaceShortcodesEvent /** * @param string $text * @param ReplacedShortcode[] $replacements + * @param ShortcodeInterface|null $shortcode */ - public function __construct($text, array $replacements, ShortcodeInterface $shortcode = null) + public function __construct($text, array $replacements, $shortcode = null) { + if(null !== $shortcode && false === $shortcode instanceof ShortcodeInterface) { + throw new \LogicException('Parameter $shortcode must be an instance of ShortcodeInterface.'); + } + $this->shortcode = $shortcode; $this->text = $text; diff --git a/src/Parser/RegexParser.php b/src/Parser/RegexParser.php index 3346680..c9e2ccb 100644 --- a/src/Parser/RegexParser.php +++ b/src/Parser/RegexParser.php @@ -21,8 +21,13 @@ final class RegexParser implements ParserInterface /** @var non-empty-string */ private $parametersRegex; - public function __construct(SyntaxInterface $syntax = null) + /** @param SyntaxInterface|null $syntax */ + public function __construct($syntax = null) { + if(null !== $syntax && false === $syntax instanceof SyntaxInterface) { + throw new \LogicException('Parameter $syntax must be an instance of SyntaxInterface.'); + } + $this->syntax = $syntax ?: new Syntax(); $this->shortcodeRegex = RegexBuilderUtility::buildShortcodeRegex($this->syntax); $this->singleShortcodeRegex = RegexBuilderUtility::buildSingleShortcodeRegex($this->syntax); diff --git a/src/Parser/RegularParser.php b/src/Parser/RegularParser.php index ca85ecc..414110e 100644 --- a/src/Parser/RegularParser.php +++ b/src/Parser/RegularParser.php @@ -35,8 +35,13 @@ final class RegularParser implements ParserInterface const TOKEN_STRING = 6; const TOKEN_WS = 7; - public function __construct(SyntaxInterface $syntax = null) + /** @param SyntaxInterface|null $syntax */ + public function __construct($syntax = null) { + if(null !== $syntax && false === $syntax instanceof SyntaxInterface) { + throw new \LogicException('Parameter $syntax must be an instance of SyntaxInterface.'); + } + $this->lexerRegex = $this->prepareLexer($syntax ?: new CommonSyntax()); $this->nameRegex = '~^'.RegexBuilderUtility::buildNameRegex().'$~us'; } diff --git a/src/Processor/Processor.php b/src/Processor/Processor.php index af68cab..3b7c418 100644 --- a/src/Processor/Processor.php +++ b/src/Processor/Processor.php @@ -86,11 +86,15 @@ private function dispatchEvent($name, $event) /** * @param string $text + * @param ProcessedShortcode|null $parent * * @return string */ - private function processIteration($text, ProcessorContext $context, ProcessedShortcode $parent = null) + private function processIteration($text, ProcessorContext $context, $parent = null) { + if(null !== $parent && false === $parent instanceof ProcessedShortcode) { + throw new \LogicException('Parameter $parent must be an instance of ProcessedShortcode.'); + } if (null !== $this->recursionDepth && $context->recursionLevel > $this->recursionDepth) { return $text; } diff --git a/src/Serializer/TextSerializer.php b/src/Serializer/TextSerializer.php index 7d93acf..540a852 100644 --- a/src/Serializer/TextSerializer.php +++ b/src/Serializer/TextSerializer.php @@ -15,8 +15,13 @@ final class TextSerializer implements SerializerInterface /** @var SyntaxInterface */ private $syntax; - public function __construct(SyntaxInterface $syntax = null) + /** @param SyntaxInterface|null $syntax */ + public function __construct($syntax = null) { + if(null !== $syntax && false === $syntax instanceof SyntaxInterface) { + throw new \LogicException('Parameter $syntax must be an instance of SyntaxInterface.'); + } + $this->syntax = $syntax ?: new Syntax(); }