Skip to content

Commit 0b988d2

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent 17dd3cb commit 0b988d2

File tree

14 files changed

+55
-223
lines changed

14 files changed

+55
-223
lines changed

config/phpstan-baseline.neon

Lines changed: 12 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
@@ -120,6 +66,18 @@ 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+
75+
-
76+
message: '#^Parameters should have "string" types as the only types passed to this method$#'
77+
identifier: typePerfect.narrowPublicClassMethodParamType
78+
count: 3
79+
path: ../src/OutputFormatter.php
80+
12381
-
12482
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
12583
identifier: parameter.defaultValue
@@ -198,24 +156,12 @@ parameters:
198156
count: 1
199157
path: ../src/Property/CSSNamespace.php
200158

201-
-
202-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
203-
identifier: method.notFound
204-
count: 1
205-
path: ../src/Property/Charset.php
206-
207159
-
208160
message: '#^Method Sabberworm\\CSS\\Property\\Charset\:\:atRuleArgs\(\) should return string but returns Sabberworm\\CSS\\Value\\CSSString\.$#'
209161
identifier: return.type
210162
count: 1
211163
path: ../src/Property/Charset.php
212164

213-
-
214-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
215-
identifier: method.notFound
216-
count: 1
217-
path: ../src/Property/Import.php
218-
219165
-
220166
message: '#^Only booleans are allowed in an if condition, string given\.$#'
221167
identifier: if.condNotBoolean
@@ -234,18 +180,6 @@ parameters:
234180
count: 1
235181
path: ../src/Property/Selector.php
236182

237-
-
238-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
239-
identifier: method.notFound
240-
count: 1
241-
path: ../src/Rule/Rule.php
242-
243-
-
244-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRuleName\(\)\.$#'
245-
identifier: method.notFound
246-
count: 1
247-
path: ../src/Rule/Rule.php
248-
249183
-
250184
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
251185
identifier: empty.notAllowed
@@ -276,54 +210,12 @@ parameters:
276210
count: 1
277211
path: ../src/Rule/Rule.php
278212

279-
-
280-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
281-
identifier: method.notFound
282-
count: 1
283-
path: ../src/RuleSet/AtRuleSet.php
284-
285-
-
286-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
287-
identifier: method.notFound
288-
count: 1
289-
path: ../src/RuleSet/AtRuleSet.php
290-
291213
-
292214
message: '#^Only booleans are allowed in an if condition, string given\.$#'
293215
identifier: if.condNotBoolean
294216
count: 1
295217
path: ../src/RuleSet/AtRuleSet.php
296218

297-
-
298-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
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\:\:implode\(\)\.$#'
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\:\:spaceAfterSelectorSeparator\(\)\.$#'
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\:\:spaceBeforeOpeningBrace\(\)\.$#'
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\:\:spaceBeforeSelectorSeparator\(\)\.$#'
323-
identifier: method.notFound
324-
count: 1
325-
path: ../src/RuleSet/DeclarationBlock.php
326-
327219
-
328220
message: '#^Foreach overwrites \$mSelector with its value variable\.$#'
329221
identifier: foreach.valueOverwrite
@@ -360,36 +252,6 @@ parameters:
360252
count: 2
361253
path: ../src/RuleSet/RuleSet.php
362254

363-
-
364-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
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\:\:safely\(\)\.$#'
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\:\:spaceAfterRules\(\)\.$#'
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\:\:spaceBeforeRules\(\)\.$#'
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\:\:spaceBetweenRules\(\)\.$#'
389-
identifier: method.notFound
390-
count: 1
391-
path: ../src/RuleSet/RuleSet.php
392-
393255
-
394256
message: '#^Only booleans are allowed in a negated boolean, string\|null given\.$#'
395257
identifier: booleanNot.exprNotBoolean
@@ -432,30 +294,6 @@ parameters:
432294
count: 3
433295
path: ../src/Value/CalcFunction.php
434296

435-
-
436-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
437-
identifier: method.notFound
438-
count: 1
439-
path: ../src/Value/CalcRuleValueList.php
440-
441-
-
442-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
443-
identifier: method.notFound
444-
count: 2
445-
path: ../src/Value/Color.php
446-
447-
-
448-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
449-
identifier: method.notFound
450-
count: 1
451-
path: ../src/Value/Color.php
452-
453-
-
454-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
455-
identifier: method.notFound
456-
count: 1
457-
path: ../src/Value/Color.php
458-
459297
-
460298
message: '#^Call to method Sabberworm\\CSS\\Value\\Color\:\:hasNoneAsComponentValue\(\) with incorrect case\: HasNoneAsComponentValue$#'
461299
identifier: method.nameCase
@@ -491,21 +329,3 @@ parameters:
491329
identifier: typePerfect.narrowPublicClassMethodParamType
492330
count: 1
493331
path: ../src/Value/Size.php
494-
495-
-
496-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
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\:\:spaceAfterListArgumentSeparator\(\)\.$#'
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\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
509-
identifier: method.notFound
510-
count: 1
511-
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)