From c672a2e02925de8eed0dcaeb3a3c90d3642049a0 Mon Sep 17 00:00:00 2001 From: Christian Kuhn Date: Fri, 12 Jul 2024 17:25:35 +0200 Subject: [PATCH] [TASK] Avoid implicitly nullable method parameter Implicit nullable method parameters are deprecated with PHP 8.4. The patch prepares affected method signatures. --- src/Behavior/CdataSection.php | 2 +- src/Behavior/Comment.php | 2 +- src/Behavior/Handler/AsTextHandler.php | 2 +- src/Behavior/Handler/ClosureHandler.php | 2 +- src/Behavior/HandlerInterface.php | 2 +- src/Behavior/Tag.php | 2 +- src/Context.php | 2 +- src/Sanitizer.php | 6 +++--- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Behavior/CdataSection.php b/src/Behavior/CdataSection.php index 7640dc1..c75b225 100644 --- a/src/Behavior/CdataSection.php +++ b/src/Behavior/CdataSection.php @@ -39,7 +39,7 @@ public function getName(): string return '#cdata-section'; } - public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, Behavior $behavior = null): ?DOMNode + public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, ?Behavior $behavior = null): ?DOMNode { if (!$this->secure || $domNode === null) { return $domNode; diff --git a/src/Behavior/Comment.php b/src/Behavior/Comment.php index e271943..482c882 100644 --- a/src/Behavior/Comment.php +++ b/src/Behavior/Comment.php @@ -39,7 +39,7 @@ public function getName(): string return '#comment'; } - public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, Behavior $behavior = null): ?DOMNode + public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, ?Behavior $behavior = null): ?DOMNode { if (!$this->secure || $domNode === null) { return $domNode; diff --git a/src/Behavior/Handler/AsTextHandler.php b/src/Behavior/Handler/AsTextHandler.php index ef6d32f..8b7963c 100644 --- a/src/Behavior/Handler/AsTextHandler.php +++ b/src/Behavior/Handler/AsTextHandler.php @@ -23,7 +23,7 @@ class AsTextHandler implements HandlerInterface { - public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, Behavior $behavior = null): ?DOMNode + public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, ?Behavior $behavior = null): ?DOMNode { if ($domNode === null) { return null; diff --git a/src/Behavior/Handler/ClosureHandler.php b/src/Behavior/Handler/ClosureHandler.php index 04ac806..44bc4ab 100644 --- a/src/Behavior/Handler/ClosureHandler.php +++ b/src/Behavior/Handler/ClosureHandler.php @@ -34,7 +34,7 @@ public function __construct(Closure $closure) $this->closure = $closure; } - public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, Behavior $behavior = null): ?DOMNode + public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, ?Behavior $behavior = null): ?DOMNode { $result = call_user_func($this->closure, $node, $domNode, $context, $behavior); if ($result !== null && !$result instanceof DOMNode) { diff --git a/src/Behavior/HandlerInterface.php b/src/Behavior/HandlerInterface.php index 7387bfa..dcaf8de 100644 --- a/src/Behavior/HandlerInterface.php +++ b/src/Behavior/HandlerInterface.php @@ -20,5 +20,5 @@ interface HandlerInterface { - public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, Behavior $behavior = null): ?DOMNode; + public function handle(NodeInterface $node, ?DOMNode $domNode, Context $context, ?Behavior $behavior = null): ?DOMNode; } diff --git a/src/Behavior/Tag.php b/src/Behavior/Tag.php index cb84033..22083d8 100644 --- a/src/Behavior/Tag.php +++ b/src/Behavior/Tag.php @@ -62,7 +62,7 @@ class Tag implements NodeInterface */ protected $attrs = []; - public function __construct(string $name, int $flags = null) + public function __construct(string $name, ?int $flags = null) { $this->name = $name; // using `null` as default - potentially allows switching diff --git a/src/Context.php b/src/Context.php index 586ee54..6a6ba8c 100644 --- a/src/Context.php +++ b/src/Context.php @@ -32,7 +32,7 @@ class Context */ public $initiator; - public function __construct(HTML5 $parser, InitiatorInterface $initiator = null) + public function __construct(HTML5 $parser, ?InitiatorInterface $initiator = null) { $this->parser = $parser; $this->initiator = $initiator; diff --git a/src/Sanitizer.php b/src/Sanitizer.php index 0f7d2a9..08c2232 100644 --- a/src/Sanitizer.php +++ b/src/Sanitizer.php @@ -92,7 +92,7 @@ public function __construct(...$items) $this->parser = $this->createParser(); } - public function sanitize(string $html, InitiatorInterface $initiator = null): string + public function sanitize(string $html, ?InitiatorInterface $initiator = null): string { $root = $this->parse($html); // @todo drop deprecated property @@ -109,7 +109,7 @@ protected function parse(string $html): DOMDocumentFragment return $this->parser->parseFragment($html); } - protected function handle(DOMNode $domNode, InitiatorInterface $initiator = null): DOMNode + protected function handle(DOMNode $domNode, ?InitiatorInterface $initiator = null): DOMNode { $this->context = new Context($this->parser, $initiator); $this->beforeTraverse(); @@ -195,7 +195,7 @@ protected function replaceNode(DOMNode $source, ?DOMNode $target): ?DOMNode return $target; } - protected function createRules(InitiatorInterface $initiator = null): Rules + protected function createRules(?InitiatorInterface $initiator = null): Rules { $stream = fopen('php://temp', 'wb'); return (new Rules($stream, self::mastermindsDefaultOptions))