Skip to content

Commit 91dfaf9

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent d71ff28 commit 91dfaf9

File tree

14 files changed

+50
-224
lines changed

14 files changed

+50
-224
lines changed

config/phpstan-baseline.neon

Lines changed: 7 additions & 193 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
@@ -120,10 +66,16 @@ parameters:
12066
count: 4
12167
path: ../src/OutputFormat.php
12268

69+
-
70+
message: '#^Parameters should have "callable" types as the only types passed to this method$#'
71+
identifier: typePerfect.narrowPublicClassMethodParamType
72+
count: 1
73+
path: ../src/OutputFormatter.php
74+
12375
-
12476
message: '#^Parameters should have "string" types as the only types passed to this method$#'
12577
identifier: typePerfect.narrowPublicClassMethodParamType
126-
count: 2
78+
count: 3
12779
path: ../src/OutputFormatter.php
12880

12981
-
@@ -204,24 +156,12 @@ parameters:
204156
count: 1
205157
path: ../src/Property/CSSNamespace.php
206158

207-
-
208-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
209-
identifier: method.notFound
210-
count: 1
211-
path: ../src/Property/Charset.php
212-
213159
-
214160
message: '#^Method Sabberworm\\CSS\\Property\\Charset\:\:atRuleArgs\(\) should return string but returns Sabberworm\\CSS\\Value\\CSSString\.$#'
215161
identifier: return.type
216162
count: 1
217163
path: ../src/Property/Charset.php
218164

219-
-
220-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
221-
identifier: method.notFound
222-
count: 1
223-
path: ../src/Property/Import.php
224-
225165
-
226166
message: '#^Only booleans are allowed in an if condition, string given\.$#'
227167
identifier: if.condNotBoolean
@@ -240,18 +180,6 @@ parameters:
240180
count: 1
241181
path: ../src/Property/Selector.php
242182

243-
-
244-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
245-
identifier: method.notFound
246-
count: 1
247-
path: ../src/Rule/Rule.php
248-
249-
-
250-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRuleName\(\)\.$#'
251-
identifier: method.notFound
252-
count: 1
253-
path: ../src/Rule/Rule.php
254-
255183
-
256184
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
257185
identifier: empty.notAllowed
@@ -282,54 +210,12 @@ parameters:
282210
count: 1
283211
path: ../src/Rule/Rule.php
284212

285-
-
286-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
287-
identifier: method.notFound
288-
count: 1
289-
path: ../src/RuleSet/AtRuleSet.php
290-
291-
-
292-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
293-
identifier: method.notFound
294-
count: 1
295-
path: ../src/RuleSet/AtRuleSet.php
296-
297213
-
298214
message: '#^Only booleans are allowed in an if condition, string given\.$#'
299215
identifier: if.condNotBoolean
300216
count: 1
301217
path: ../src/RuleSet/AtRuleSet.php
302218

303-
-
304-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
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\:\:implode\(\)\.$#'
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\:\:spaceAfterSelectorSeparator\(\)\.$#'
317-
identifier: method.notFound
318-
count: 1
319-
path: ../src/RuleSet/DeclarationBlock.php
320-
321-
-
322-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
323-
identifier: method.notFound
324-
count: 1
325-
path: ../src/RuleSet/DeclarationBlock.php
326-
327-
-
328-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeSelectorSeparator\(\)\.$#'
329-
identifier: method.notFound
330-
count: 1
331-
path: ../src/RuleSet/DeclarationBlock.php
332-
333219
-
334220
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
335221
identifier: foreach.valueOverwrite
@@ -366,36 +252,6 @@ parameters:
366252
count: 2
367253
path: ../src/RuleSet/RuleSet.php
368254

369-
-
370-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
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\:\:safely\(\)\.$#'
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\:\:spaceAfterRules\(\)\.$#'
383-
identifier: method.notFound
384-
count: 1
385-
path: ../src/RuleSet/RuleSet.php
386-
387-
-
388-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeRules\(\)\.$#'
389-
identifier: method.notFound
390-
count: 1
391-
path: ../src/RuleSet/RuleSet.php
392-
393-
-
394-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenRules\(\)\.$#'
395-
identifier: method.notFound
396-
count: 1
397-
path: ../src/RuleSet/RuleSet.php
398-
399255
-
400256
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
401257
identifier: booleanNot.exprNotBoolean
@@ -438,30 +294,6 @@ parameters:
438294
count: 3
439295
path: ../src/Value/CalcFunction.php
440296

441-
-
442-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
443-
identifier: method.notFound
444-
count: 1
445-
path: ../src/Value/CalcRuleValueList.php
446-
447-
-
448-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
449-
identifier: method.notFound
450-
count: 2
451-
path: ../src/Value/Color.php
452-
453-
-
454-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
455-
identifier: method.notFound
456-
count: 1
457-
path: ../src/Value/Color.php
458-
459-
-
460-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
461-
identifier: method.notFound
462-
count: 1
463-
path: ../src/Value/Color.php
464-
465297
-
466298
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
467299
identifier: method.nameCase
@@ -497,21 +329,3 @@ parameters:
497329
identifier: typePerfect.narrowPublicClassMethodParamType
498330
count: 1
499331
path: ../src/Value/Size.php
500-
501-
-
502-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
503-
identifier: method.notFound
504-
count: 1
505-
path: ../src/Value/ValueList.php
506-
507-
-
508-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
509-
identifier: method.notFound
510-
count: 1
511-
path: ../src/Value/ValueList.php
512-
513-
-
514-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
515-
identifier: method.notFound
516-
count: 1
517-
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 {

0 commit comments

Comments
 (0)