Skip to content

Commit 292351c

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent 3e9bc30 commit 292351c

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,24 +36,6 @@ 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-
81-
-
82-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
83-
identifier: method.notFound
84-
count: 1
85-
path: ../src/CSSList/KeyFrame.php
86-
87-
-
88-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
89-
identifier: method.notFound
90-
count: 1
91-
path: ../src/CSSList/KeyFrame.php
92-
9339
-
9440
message: '#^Variable property access on \$this\(Sabberworm\\CSS\\OutputFormat\)\.$#'
9541
identifier: property.dynamicName
@@ -150,24 +96,12 @@ parameters:
15096
count: 1
15197
path: ../src/Property/CSSNamespace.php
15298

153-
-
154-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
155-
identifier: method.notFound
156-
count: 1
157-
path: ../src/Property/Charset.php
158-
15999
-
160100
message: '#^Method Sabberworm\\CSS\\Property\\Charset\:\:atRuleArgs\(\) should return string but returns Sabberworm\\CSS\\Value\\CSSString\.$#'
161101
identifier: return.type
162102
count: 1
163103
path: ../src/Property/Charset.php
164104

165-
-
166-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
167-
identifier: method.notFound
168-
count: 1
169-
path: ../src/Property/Import.php
170-
171105
-
172106
message: '#^Only booleans are allowed in an if condition, string given\.$#'
173107
identifier: if.condNotBoolean
@@ -180,18 +114,6 @@ parameters:
180114
count: 1
181115
path: ../src/Property/Import.php
182116

183-
-
184-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
185-
identifier: method.notFound
186-
count: 1
187-
path: ../src/Rule/Rule.php
188-
189-
-
190-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRuleName\(\)\.$#'
191-
identifier: method.notFound
192-
count: 1
193-
path: ../src/Rule/Rule.php
194-
195117
-
196118
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
197119
identifier: empty.notAllowed
@@ -204,54 +126,12 @@ parameters:
204126
count: 1
205127
path: ../src/Rule/Rule.php
206128

207-
-
208-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
209-
identifier: method.notFound
210-
count: 1
211-
path: ../src/RuleSet/AtRuleSet.php
212-
213-
-
214-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
215-
identifier: method.notFound
216-
count: 1
217-
path: ../src/RuleSet/AtRuleSet.php
218-
219129
-
220130
message: '#^Only booleans are allowed in an if condition, string given\.$#'
221131
identifier: if.condNotBoolean
222132
count: 1
223133
path: ../src/RuleSet/AtRuleSet.php
224134

225-
-
226-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
227-
identifier: method.notFound
228-
count: 1
229-
path: ../src/RuleSet/DeclarationBlock.php
230-
231-
-
232-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
233-
identifier: method.notFound
234-
count: 1
235-
path: ../src/RuleSet/DeclarationBlock.php
236-
237-
-
238-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterSelectorSeparator\(\)\.$#'
239-
identifier: method.notFound
240-
count: 1
241-
path: ../src/RuleSet/DeclarationBlock.php
242-
243-
-
244-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
245-
identifier: method.notFound
246-
count: 1
247-
path: ../src/RuleSet/DeclarationBlock.php
248-
249-
-
250-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeSelectorSeparator\(\)\.$#'
251-
identifier: method.notFound
252-
count: 1
253-
path: ../src/RuleSet/DeclarationBlock.php
254-
255135
-
256136
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
257137
identifier: foreach.valueOverwrite
@@ -276,36 +156,6 @@ parameters:
276156
count: 2
277157
path: ../src/RuleSet/RuleSet.php
278158

279-
-
280-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
281-
identifier: method.notFound
282-
count: 1
283-
path: ../src/RuleSet/RuleSet.php
284-
285-
-
286-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
287-
identifier: method.notFound
288-
count: 1
289-
path: ../src/RuleSet/RuleSet.php
290-
291-
-
292-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRules\(\)\.$#'
293-
identifier: method.notFound
294-
count: 1
295-
path: ../src/RuleSet/RuleSet.php
296-
297-
-
298-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeRules\(\)\.$#'
299-
identifier: method.notFound
300-
count: 1
301-
path: ../src/RuleSet/RuleSet.php
302-
303-
-
304-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenRules\(\)\.$#'
305-
identifier: method.notFound
306-
count: 1
307-
path: ../src/RuleSet/RuleSet.php
308-
309159
-
310160
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
311161
identifier: booleanNot.exprNotBoolean
@@ -330,30 +180,6 @@ parameters:
330180
count: 3
331181
path: ../src/Value/CalcFunction.php
332182

333-
-
334-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
335-
identifier: method.notFound
336-
count: 1
337-
path: ../src/Value/CalcRuleValueList.php
338-
339-
-
340-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
341-
identifier: method.notFound
342-
count: 2
343-
path: ../src/Value/Color.php
344-
345-
-
346-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
347-
identifier: method.notFound
348-
count: 1
349-
path: ../src/Value/Color.php
350-
351-
-
352-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
353-
identifier: method.notFound
354-
count: 1
355-
path: ../src/Value/Color.php
356-
357183
-
358184
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
359185
identifier: method.nameCase
@@ -377,21 +203,3 @@ parameters:
377203
identifier: notEqual.notAllowed
378204
count: 1
379205
path: ../src/Value/Size.php
380-
381-
-
382-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
383-
identifier: method.notFound
384-
count: 1
385-
path: ../src/Value/ValueList.php
386-
387-
-
388-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
389-
identifier: method.notFound
390-
count: 1
391-
path: ../src/Value/ValueList.php
392-
393-
-
394-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
395-
identifier: method.notFound
396-
count: 1
397-
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
@@ -113,7 +113,7 @@ public function render(?OutputFormat $outputFormat = null): string
113113
if ($outputFormat === null) {
114114
$outputFormat = new OutputFormat();
115115
}
116-
return $outputFormat->comments($this) . $this->renderListContents($outputFormat);
116+
return $outputFormat->getFormatter()->comments($this) . $this->renderListContents($outputFormat);
117117
}
118118

119119
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)