From 519b7b646f4d9c4656da0be2c7b7467b68236c60 Mon Sep 17 00:00:00 2001 From: HorstOeko Date: Wed, 28 Aug 2024 09:09:47 +0200 Subject: [PATCH] Added helper metjpd fireCallback to XmlNodeList --- src/xml/XmlNodeList.php | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/xml/XmlNodeList.php b/src/xml/XmlNodeList.php index 0257a52..1aa75fb 100644 --- a/src/xml/XmlNodeList.php +++ b/src/xml/XmlNodeList.php @@ -82,13 +82,7 @@ public function forEachMax(int $max, $callback, $callBackBefore = null, $callbac return; } - if (!is_callable($callback)) { - return; - } - - if (is_callable($callBackBefore)) { - call_user_func($callBackBefore); - } + $this->fireCallback($callBackBefore); $count = 0; @@ -99,19 +93,27 @@ public function forEachMax(int $max, $callback, $callBackBefore = null, $callbac break; } - if (is_callable($callbackBeforeEach)) { - call_user_func($callbackBeforeEach, $node); - } + $this->fireCallback($callbackBeforeEach, $node); + $this->fireCallback($callback, $node); + $this->fireCallback($callbackAfterEach, $node); + } - call_user_func($callback, $node); + $this->fireCallback($callbackAfter); + } - if (is_callable($callbackAfterEach)) { - call_user_func($callbackAfterEach, $node); - } + /** + * Internal helper function to fire a callback function + * + * @param callable $callback + * @param array ...$args + * @return void + */ + private function fireCallback($callback, ...$args) + { + if (!is_callable($callback)) { + return; } - if (is_callable($callbackAfter)) { - call_user_func($callbackAfter); - } + call_user_func($callback, ...$args); } }