Skip to content

Commit 9dec5c0

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent ce0a049 commit 9dec5c0

File tree

14 files changed

+43
-223
lines changed

14 files changed

+43
-223
lines changed

config/phpstan-baseline.neon

Lines changed: 0 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
parameters:
22
ignoreErrors:
3-
-
4-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
5-
identifier: method.notFound
6-
count: 1
7-
path: ../src/CSSList/AtRuleBlockList.php
8-
9-
-
10-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
11-
identifier: method.notFound
12-
count: 1
13-
path: ../src/CSSList/AtRuleBlockList.php
14-
153
-
164
message: '#^Only booleans are allowed in an if condition, string given\.$#'
175
identifier: if.condNotBoolean
@@ -30,30 +18,6 @@ parameters:
3018
count: 1
3119
path: ../src/CSSList/CSSBlockList.php
3220

33-
-
34-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
35-
identifier: method.notFound
36-
count: 1
37-
path: ../src/CSSList/CSSList.php
38-
39-
-
40-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterBlocks\(\)\.$#'
41-
identifier: method.notFound
42-
count: 1
43-
path: ../src/CSSList/CSSList.php
44-
45-
-
46-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeBlocks\(\)\.$#'
47-
identifier: method.notFound
48-
count: 1
49-
path: ../src/CSSList/CSSList.php
50-
51-
-
52-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenBlocks\(\)\.$#'
53-
identifier: method.notFound
54-
count: 1
55-
path: ../src/CSSList/CSSList.php
56-
5721
-
5822
message: '#^Loose comparison via "\!\=" is not allowed\.$#'
5923
identifier: notEqual.notAllowed
@@ -72,30 +36,12 @@ parameters:
7236
count: 1
7337
path: ../src/CSSList/CSSList.php
7438

75-
-
76-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
77-
identifier: method.notFound
78-
count: 1
79-
path: ../src/CSSList/Document.php
80-
8139
-
8240
message: '#^Parameters should have "string\|null" types as the only types passed to this method$#'
8341
identifier: typePerfect.narrowPublicClassMethodParamType
8442
count: 1
8543
path: ../src/CSSList/Document.php
8644

87-
-
88-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
89-
identifier: method.notFound
90-
count: 1
91-
path: ../src/CSSList/KeyFrame.php
92-
93-
-
94-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
95-
identifier: method.notFound
96-
count: 1
97-
path: ../src/CSSList/KeyFrame.php
98-
9945
-
10046
message: '#^Parameters should have "string" types as the only types passed to this method$#'
10147
identifier: typePerfect.narrowPublicClassMethodParamType
@@ -192,24 +138,12 @@ parameters:
192138
count: 1
193139
path: ../src/Property/CSSNamespace.php
194140

195-
-
196-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
197-
identifier: method.notFound
198-
count: 1
199-
path: ../src/Property/Charset.php
200-
201141
-
202142
message: '#^Method Sabberworm\\CSS\\Property\\Charset\:\:atRuleArgs\(\) should return string but returns Sabberworm\\CSS\\Value\\CSSString\.$#'
203143
identifier: return.type
204144
count: 1
205145
path: ../src/Property/Charset.php
206146

207-
-
208-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
209-
identifier: method.notFound
210-
count: 1
211-
path: ../src/Property/Import.php
212-
213147
-
214148
message: '#^Only booleans are allowed in an if condition, string given\.$#'
215149
identifier: if.condNotBoolean
@@ -228,18 +162,6 @@ parameters:
228162
count: 1
229163
path: ../src/Property/Selector.php
230164

231-
-
232-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
233-
identifier: method.notFound
234-
count: 1
235-
path: ../src/Rule/Rule.php
236-
237-
-
238-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRuleName\(\)\.$#'
239-
identifier: method.notFound
240-
count: 1
241-
path: ../src/Rule/Rule.php
242-
243165
-
244166
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
245167
identifier: empty.notAllowed
@@ -270,54 +192,12 @@ parameters:
270192
count: 1
271193
path: ../src/Rule/Rule.php
272194

273-
-
274-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
275-
identifier: method.notFound
276-
count: 1
277-
path: ../src/RuleSet/AtRuleSet.php
278-
279-
-
280-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
281-
identifier: method.notFound
282-
count: 1
283-
path: ../src/RuleSet/AtRuleSet.php
284-
285195
-
286196
message: '#^Only booleans are allowed in an if condition, string given\.$#'
287197
identifier: if.condNotBoolean
288198
count: 1
289199
path: ../src/RuleSet/AtRuleSet.php
290200

291-
-
292-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
293-
identifier: method.notFound
294-
count: 1
295-
path: ../src/RuleSet/DeclarationBlock.php
296-
297-
-
298-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
299-
identifier: method.notFound
300-
count: 1
301-
path: ../src/RuleSet/DeclarationBlock.php
302-
303-
-
304-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterSelectorSeparator\(\)\.$#'
305-
identifier: method.notFound
306-
count: 1
307-
path: ../src/RuleSet/DeclarationBlock.php
308-
309-
-
310-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
311-
identifier: method.notFound
312-
count: 1
313-
path: ../src/RuleSet/DeclarationBlock.php
314-
315-
-
316-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeSelectorSeparator\(\)\.$#'
317-
identifier: method.notFound
318-
count: 1
319-
path: ../src/RuleSet/DeclarationBlock.php
320-
321201
-
322202
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
323203
identifier: foreach.valueOverwrite
@@ -354,36 +234,6 @@ parameters:
354234
count: 2
355235
path: ../src/RuleSet/RuleSet.php
356236

357-
-
358-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
359-
identifier: method.notFound
360-
count: 1
361-
path: ../src/RuleSet/RuleSet.php
362-
363-
-
364-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
365-
identifier: method.notFound
366-
count: 1
367-
path: ../src/RuleSet/RuleSet.php
368-
369-
-
370-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRules\(\)\.$#'
371-
identifier: method.notFound
372-
count: 1
373-
path: ../src/RuleSet/RuleSet.php
374-
375-
-
376-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeRules\(\)\.$#'
377-
identifier: method.notFound
378-
count: 1
379-
path: ../src/RuleSet/RuleSet.php
380-
381-
-
382-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenRules\(\)\.$#'
383-
identifier: method.notFound
384-
count: 1
385-
path: ../src/RuleSet/RuleSet.php
386-
387237
-
388238
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
389239
identifier: booleanNot.exprNotBoolean
@@ -426,30 +276,6 @@ parameters:
426276
count: 3
427277
path: ../src/Value/CalcFunction.php
428278

429-
-
430-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
431-
identifier: method.notFound
432-
count: 1
433-
path: ../src/Value/CalcRuleValueList.php
434-
435-
-
436-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
437-
identifier: method.notFound
438-
count: 2
439-
path: ../src/Value/Color.php
440-
441-
-
442-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
443-
identifier: method.notFound
444-
count: 1
445-
path: ../src/Value/Color.php
446-
447-
-
448-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
449-
identifier: method.notFound
450-
count: 1
451-
path: ../src/Value/Color.php
452-
453279
-
454280
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
455281
identifier: method.nameCase
@@ -485,21 +311,3 @@ parameters:
485311
identifier: typePerfect.narrowPublicClassMethodParamType
486312
count: 1
487313
path: ../src/Value/Size.php
488-
489-
-
490-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
491-
identifier: method.notFound
492-
count: 1
493-
path: ../src/Value/ValueList.php
494-
495-
-
496-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
497-
identifier: method.notFound
498-
count: 1
499-
path: ../src/Value/ValueList.php
500-
501-
-
502-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
503-
identifier: method.notFound
504-
count: 1
505-
path: ../src/Value/ValueList.php

src/CSSList/AtRuleBlockList.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,14 @@ public function __toString(): string
5757

5858
public function render(OutputFormat $outputFormat): string
5959
{
60-
$result = $outputFormat->comments($this);
60+
$formatter = $outputFormat->getFormatter();
61+
$result = $formatter->comments($this);
6162
$result .= $outputFormat->sBeforeAtRuleBlock;
6263
$arguments = $this->arguments;
6364
if ($arguments) {
6465
$arguments = ' ' . $arguments;
6566
}
66-
$result .= "@{$this->type}$arguments{$outputFormat->spaceBeforeOpeningBrace()}{";
67+
$result .= "@{$this->type}$arguments{$formatter->spaceBeforeOpeningBrace()}{";
6768
$result .= $this->renderListContents($outputFormat);
6869
$result .= '}';
6970
$result .= $outputFormat->sAfterAtRuleBlock;

src/CSSList/CSSList.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -418,25 +418,27 @@ protected function renderListContents(OutputFormat $outputFormat)
418418
if (!$this->isRootList()) {
419419
$nextLevelFormat = $outputFormat->nextLevel();
420420
}
421+
$nextLevelFormatter = $nextLevelFormat->getFormatter();
422+
$formatter = $outputFormat->getFormatter();
421423
foreach ($this->contents as $listItem) {
422-
$renderedCss = $outputFormat->safely(static function () use ($nextLevelFormat, $listItem): string {
424+
$renderedCss = $formatter->safely(static function () use ($nextLevelFormat, $listItem): string {
423425
return $listItem->render($nextLevelFormat);
424426
});
425427
if ($renderedCss === null) {
426428
continue;
427429
}
428430
if ($isFirst) {
429431
$isFirst = false;
430-
$result .= $nextLevelFormat->spaceBeforeBlocks();
432+
$result .= $nextLevelFormatter->spaceBeforeBlocks();
431433
} else {
432-
$result .= $nextLevelFormat->spaceBetweenBlocks();
434+
$result .= $nextLevelFormatter->spaceBetweenBlocks();
433435
}
434436
$result .= $renderedCss;
435437
}
436438

437439
if (!$isFirst) {
438440
// Had some output
439-
$result .= $outputFormat->spaceAfterBlocks();
441+
$result .= $formatter->spaceAfterBlocks();
440442
}
441443

442444
return $result;

src/CSSList/Document.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public function render(?OutputFormat $outputFormat = null): string
112112
if ($outputFormat === null) {
113113
$outputFormat = new OutputFormat();
114114
}
115-
return $outputFormat->comments($this) . $this->renderListContents($outputFormat);
115+
return $outputFormat->getFormatter()->comments($this) . $this->renderListContents($outputFormat);
116116
}
117117

118118
public function isRootList(): bool

src/CSSList/KeyFrame.php

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

5959
public function render(OutputFormat $outputFormat): string
6060
{
61-
$result = $outputFormat->comments($this);
62-
$result .= "@{$this->vendorKeyFrame} {$this->animationName}{$outputFormat->spaceBeforeOpeningBrace()}{";
61+
$formatter = $outputFormat->getFormatter();
62+
$result = $formatter->comments($this);
63+
$result .= "@{$this->vendorKeyFrame} {$this->animationName}{$formatter->spaceBeforeOpeningBrace()}{";
6364
$result .= $this->renderListContents($outputFormat);
6465
$result .= '}';
6566
return $result;

src/Property/Charset.php

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

7979
public function render(OutputFormat $outputFormat): string
8080
{
81-
return "{$outputFormat->comments($this)}@charset {$this->oCharset->render($outputFormat)};";
81+
return "{$outputFormat->getFormatter()->comments($this)}@charset {$this->oCharset->render($outputFormat)};";
8282
}
8383

8484
public function atRuleName(): string

src/Property/Import.php

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

8080
public function render(OutputFormat $outputFormat): string
8181
{
82-
return $outputFormat->comments($this) . '@import ' . $this->location->render($outputFormat)
82+
return $outputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($outputFormat)
8383
. ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';';
8484
}
8585

src/Rule/Rule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ public function __toString(): string
267267

268268
public function render(OutputFormat $outputFormat): string
269269
{
270-
$result = "{$outputFormat->comments($this)}{$this->sRule}:{$outputFormat->spaceAfterRuleName()}";
270+
$formatter = $outputFormat->getFormatter();
271+
$result = "{$formatter->comments($this)}{$this->sRule}:{$formatter->spaceAfterRuleName()}";
271272
if ($this->mValue instanceof Value) { // Can also be a ValueList
272273
$result .= $this->mValue->render($outputFormat);
273274
} else {

src/RuleSet/AtRuleSet.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,13 @@ public function __toString(): string
6060

6161
public function render(OutputFormat $outputFormat): string
6262
{
63-
$result = $outputFormat->comments($this);
63+
$formatter = $outputFormat->getFormatter();
64+
$result = $formatter->comments($this);
6465
$arguments = $this->arguments;
6566
if ($arguments) {
6667
$arguments = ' ' . $arguments;
6768
}
68-
$result .= "@{$this->sType}$arguments{$outputFormat->spaceBeforeOpeningBrace()}{";
69+
$result .= "@{$this->sType}$arguments{$formatter->spaceBeforeOpeningBrace()}{";
6970
$result .= $this->renderRules($outputFormat);
7071
$result .= '}';
7172
return $result;

0 commit comments

Comments
 (0)