From 04b5cc5929d671719ecf5b3a7c0a4074644babe6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 12 Mar 2025 16:55:09 +0100 Subject: [PATCH] [CLEANUP] Avoid magic method forwarding in `CSSList` Part of #1147 --- config/phpstan-baseline.neon | 24 ------------------------ src/CSSList/CSSList.php | 10 ++++++---- 2 files changed, 6 insertions(+), 28 deletions(-) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index 435a4cd3..c3bc09da 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -18,30 +18,6 @@ parameters: count: 1 path: ../src/CSSList/CSSBlockList.php - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/CSSList/CSSList.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterBlocks\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/CSSList/CSSList.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeBlocks\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/CSSList/CSSList.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenBlocks\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/CSSList/CSSList.php - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index 1af21f85..15a5e87a 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -419,8 +419,10 @@ protected function renderListContents(OutputFormat $outputFormat) if (!$this->isRootList()) { $nextLevelFormat = $outputFormat->nextLevel(); } + $nextLevelFormatter = $nextLevelFormat->getFormatter(); + $formatter = $outputFormat->getFormatter(); foreach ($this->contents as $listItem) { - $renderedCss = $outputFormat->safely(static function () use ($nextLevelFormat, $listItem): string { + $renderedCss = $formatter->safely(static function () use ($nextLevelFormat, $listItem): string { return $listItem->render($nextLevelFormat); }); if ($renderedCss === null) { @@ -428,16 +430,16 @@ protected function renderListContents(OutputFormat $outputFormat) } if ($isFirst) { $isFirst = false; - $result .= $nextLevelFormat->spaceBeforeBlocks(); + $result .= $nextLevelFormatter->spaceBeforeBlocks(); } else { - $result .= $nextLevelFormat->spaceBetweenBlocks(); + $result .= $nextLevelFormatter->spaceBetweenBlocks(); } $result .= $renderedCss; } if (!$isFirst) { // Had some output - $result .= $outputFormat->spaceAfterBlocks(); + $result .= $formatter->spaceAfterBlocks(); } return $result;