Skip to content

Commit 336d726

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent 230fd2a commit 336d726

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

src/CSSList/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function render(?OutputFormat $outputFormat = null): string
8686
if ($outputFormat === null) {
8787
$outputFormat = new OutputFormat();
8888
}
89-
return $outputFormat->comments($this) . $this->renderListContents($outputFormat);
89+
return $outputFormat->getFormatter()->comments($this) . $this->renderListContents($outputFormat);
9090
}
9191

9292
public function isRootList(): bool

src/CSSList/KeyFrame.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public function __toString(): string
6161

6262
public function render(OutputFormat $outputFormat): string
6363
{
64-
$result = $outputFormat->comments($this);
65-
$result .= "@{$this->vendorKeyFrame} {$this->animationName}{$outputFormat->spaceBeforeOpeningBrace()}{";
64+
$formatter = $outputFormat->getFormatter();
65+
$result = $formatter->comments($this);
66+
$result .= "@{$this->vendorKeyFrame} {$this->animationName}{$formatter->spaceBeforeOpeningBrace()}{";
6667
$result .= $this->renderListContents($outputFormat);
6768
$result .= '}';
6869
return $result;

src/Property/Charset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function __toString(): string
8181

8282
public function render(OutputFormat $outputFormat): string
8383
{
84-
return "{$outputFormat->comments($this)}@charset {$this->charset->render($outputFormat)};";
84+
return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->charset->render($outputFormat)};";
8585
}
8686

8787
/**

src/Property/Import.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __toString(): string
8282

8383
public function render(OutputFormat $outputFormat): string
8484
{
85-
return $outputFormat->comments($this) . '@import ' . $this->location->render($outputFormat)
85+
return $outputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($outputFormat)
8686
. ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';';
8787
}
8888

src/RuleSet/DeclarationBlock.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,21 +155,23 @@ public function __toString(): string
155155
*/
156156
public function render(OutputFormat $outputFormat): string
157157
{
158-
$result = $outputFormat->comments($this);
158+
$formatter = $outputFormat->getFormatter();
159+
$result = $formatter->comments($this);
159160
if (\count($this->selectors) === 0) {
160161
// If all the selectors have been removed, this declaration block becomes invalid
161162
throw new OutputException('Attempt to print declaration block with missing selector', $this->lineNumber);
162163
}
163164
$result .= $outputFormat->getContentBeforeDeclarationBlock();
164-
$result .= $outputFormat->implode(
165-
$outputFormat->spaceBeforeSelectorSeparator() . ',' . $outputFormat->spaceAfterSelectorSeparator(),
165+
$result .= $formatter->implode(
166+
$formatter->spaceBeforeSelectorSeparator() . ',' . $formatter->spaceAfterSelectorSeparator(),
166167
$this->selectors
167168
);
168169
$result .= $outputFormat->getContentAfterDeclarationBlockSelectors();
169-
$result .= $outputFormat->spaceBeforeOpeningBrace() . '{';
170+
$result .= $formatter->spaceBeforeOpeningBrace() . '{';
170171
$result .= $this->renderRules($outputFormat);
171172
$result .= '}';
172173
$result .= $outputFormat->getContentAfterDeclarationBlock();
174+
173175
return $result;
174176
}
175177
}

src/RuleSet/RuleSet.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,27 +278,29 @@ protected function renderRules(OutputFormat $outputFormat)
278278
$isFirst = true;
279279
$nextLevelFormat = $outputFormat->nextLevel();
280280
foreach ($this->getRules() as $rule) {
281-
$renderedRule = $nextLevelFormat->safely(static function () use ($rule, $nextLevelFormat): string {
282-
return $rule->render($nextLevelFormat);
283-
});
281+
$renderedRule = $nextLevelFormat->getFormatter()
282+
->safely(static function () use ($rule, $nextLevelFormat): string {
283+
return $rule->render($nextLevelFormat);
284+
});
284285
if ($renderedRule === null) {
285286
continue;
286287
}
287288
if ($isFirst) {
288289
$isFirst = false;
289-
$result .= $nextLevelFormat->spaceBeforeRules();
290+
$result .= $nextLevelFormat->getFormatter()->spaceBeforeRules();
290291
} else {
291-
$result .= $nextLevelFormat->spaceBetweenRules();
292+
$result .= $nextLevelFormat->getFormatter()->spaceBetweenRules();
292293
}
293294
$result .= $renderedRule;
294295
}
295296

297+
$formatter = $outputFormat->getFormatter();
296298
if (!$isFirst) {
297299
// Had some output
298-
$result .= $outputFormat->spaceAfterRules();
300+
$result .= $formatter->spaceAfterRules();
299301
}
300302

301-
return $outputFormat->removeLastSemicolon($result);
303+
return $formatter->removeLastSemicolon($result);
302304
}
303305

304306
/**

src/Value/CalcRuleValueList.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function __construct(int $lineNumber = 0)
1818

1919
public function render(OutputFormat $outputFormat): string
2020
{
21-
return $outputFormat->implode(' ', $this->components);
21+
return $outputFormat->getFormatter()->implode(' ', $this->components);
2222
}
2323
}

0 commit comments

Comments
 (0)