From 15ca7dc65f02a00d31c93f08507fb88cdfb58bd6 Mon Sep 17 00:00:00 2001 From: Oliver Klee Date: Wed, 12 Mar 2025 18:51:53 +0100 Subject: [PATCH] [CLEANUP] Avoid magic method forwarding in `DeclarationBlock` Part of #1147 --- config/phpstan-baseline.neon | 30 ------------------------------ src/RuleSet/DeclarationBlock.php | 10 ++++++---- 2 files changed, 6 insertions(+), 34 deletions(-) diff --git a/config/phpstan-baseline.neon b/config/phpstan-baseline.neon index b527ad4b5..920f31e74 100644 --- a/config/phpstan-baseline.neon +++ b/config/phpstan-baseline.neon @@ -108,36 +108,6 @@ parameters: count: 1 path: ../src/RuleSet/AtRuleSet.php - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterSelectorSeparator\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - - - message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeSelectorSeparator\(\)\.$#' - identifier: method.notFound - count: 1 - path: ../src/RuleSet/DeclarationBlock.php - - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index 4bd45d686..295167648 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -155,21 +155,23 @@ public function __toString(): string */ public function render(OutputFormat $outputFormat): string { - $result = $outputFormat->comments($this); + $formatter = $outputFormat->getFormatter(); + $result = $formatter->comments($this); if (\count($this->selectors) === 0) { // If all the selectors have been removed, this declaration block becomes invalid throw new OutputException('Attempt to print declaration block with missing selector', $this->lineNumber); } $result .= $outputFormat->getContentBeforeDeclarationBlock(); - $result .= $outputFormat->implode( - $outputFormat->spaceBeforeSelectorSeparator() . ',' . $outputFormat->spaceAfterSelectorSeparator(), + $result .= $formatter->implode( + $formatter->spaceBeforeSelectorSeparator() . ',' . $formatter->spaceAfterSelectorSeparator(), $this->selectors ); $result .= $outputFormat->getContentAfterDeclarationBlockSelectors(); - $result .= $outputFormat->spaceBeforeOpeningBrace() . '{'; + $result .= $formatter->spaceBeforeOpeningBrace() . '{'; $result .= $this->renderRules($outputFormat); $result .= '}'; $result .= $outputFormat->getContentAfterDeclarationBlock(); + return $result; } }