Skip to content

Commit 447e59e

Browse files
committed
[TASK] Avoid magic method forwarding in OutputFormat
1 parent b3e83b8 commit 447e59e

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,59 +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-
15-
-
16-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
17-
identifier: method.notFound
18-
count: 1
19-
path: ../src/CSSList/CSSList.php
20-
21-
-
22-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterBlocks\(\)\.$#'
23-
identifier: method.notFound
24-
count: 1
25-
path: ../src/CSSList/CSSList.php
26-
27-
-
28-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeBlocks\(\)\.$#'
29-
identifier: method.notFound
30-
count: 1
31-
path: ../src/CSSList/CSSList.php
32-
33-
-
34-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenBlocks\(\)\.$#'
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\:\:comments\(\)\.$#'
41-
identifier: method.notFound
42-
count: 1
43-
path: ../src/CSSList/Document.php
44-
45-
-
46-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
47-
identifier: method.notFound
48-
count: 1
49-
path: ../src/CSSList/KeyFrame.php
50-
51-
-
52-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
53-
identifier: method.notFound
54-
count: 1
55-
path: ../src/CSSList/KeyFrame.php
56-
573
-
584
message: '#^Default value of the parameter \#2 \$bIncludeEnd \(false\) of method Sabberworm\\CSS\\Parsing\\ParserState\:\:consumeUntil\(\) is incompatible with type string\.$#'
595
identifier: parameter.defaultValue
@@ -78,154 +24,16 @@ parameters:
7824
count: 1
7925
path: ../src/Property/CSSNamespace.php
8026

81-
-
82-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
83-
identifier: method.notFound
84-
count: 1
85-
path: ../src/Property/Charset.php
86-
8727
-
8828
message: '#^PHPDoc tag @param references unknown parameter\: \$oCharset$#'
8929
identifier: parameter.notFound
9030
count: 1
9131
path: ../src/Property/Charset.php
9232

93-
-
94-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
95-
identifier: method.notFound
96-
count: 1
97-
path: ../src/Property/Import.php
98-
99-
-
100-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
101-
identifier: method.notFound
102-
count: 1
103-
path: ../src/Rule/Rule.php
104-
105-
-
106-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRuleName\(\)\.$#'
107-
identifier: method.notFound
108-
count: 1
109-
path: ../src/Rule/Rule.php
110-
111-
-
112-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
113-
identifier: method.notFound
114-
count: 1
115-
path: ../src/RuleSet/AtRuleSet.php
116-
117-
-
118-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
119-
identifier: method.notFound
120-
count: 1
121-
path: ../src/RuleSet/AtRuleSet.php
122-
123-
-
124-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:comments\(\)\.$#'
125-
identifier: method.notFound
126-
count: 1
127-
path: ../src/RuleSet/DeclarationBlock.php
128-
129-
-
130-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
131-
identifier: method.notFound
132-
count: 1
133-
path: ../src/RuleSet/DeclarationBlock.php
134-
135-
-
136-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterSelectorSeparator\(\)\.$#'
137-
identifier: method.notFound
138-
count: 1
139-
path: ../src/RuleSet/DeclarationBlock.php
140-
141-
-
142-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeOpeningBrace\(\)\.$#'
143-
identifier: method.notFound
144-
count: 1
145-
path: ../src/RuleSet/DeclarationBlock.php
146-
147-
-
148-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeSelectorSeparator\(\)\.$#'
149-
identifier: method.notFound
150-
count: 1
151-
path: ../src/RuleSet/DeclarationBlock.php
152-
153-
-
154-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:removeLastSemicolon\(\)\.$#'
155-
identifier: method.notFound
156-
count: 1
157-
path: ../src/RuleSet/RuleSet.php
158-
159-
-
160-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:safely\(\)\.$#'
161-
identifier: method.notFound
162-
count: 1
163-
path: ../src/RuleSet/RuleSet.php
164-
165-
-
166-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterRules\(\)\.$#'
167-
identifier: method.notFound
168-
count: 1
169-
path: ../src/RuleSet/RuleSet.php
170-
171-
-
172-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeRules\(\)\.$#'
173-
identifier: method.notFound
174-
count: 1
175-
path: ../src/RuleSet/RuleSet.php
176-
177-
-
178-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBetweenRules\(\)\.$#'
179-
identifier: method.notFound
180-
count: 1
181-
path: ../src/RuleSet/RuleSet.php
182-
183-
-
184-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
185-
identifier: method.notFound
186-
count: 1
187-
path: ../src/Value/CalcRuleValueList.php
188-
189-
-
190-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
191-
identifier: method.notFound
192-
count: 2
193-
path: ../src/Value/Color.php
194-
195-
-
196-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
197-
identifier: method.notFound
198-
count: 1
199-
path: ../src/Value/Color.php
200-
201-
-
202-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
203-
identifier: method.notFound
204-
count: 1
205-
path: ../src/Value/Color.php
206-
20733
-
20834
message: '#^Cannot call method getSize\(\) on Sabberworm\\CSS\\Value\\Value\|string\.$#'
20935
identifier: method.nonObject
21036
count: 3
21137
path: ../src/Value/Color.php
21238

213-
-
214-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:implode\(\)\.$#'
215-
identifier: method.notFound
216-
count: 1
217-
path: ../src/Value/ValueList.php
218-
219-
-
220-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceAfterListArgumentSeparator\(\)\.$#'
221-
identifier: method.notFound
222-
count: 1
223-
path: ../src/Value/ValueList.php
224-
225-
-
226-
message: '#^Call to an undefined method Sabberworm\\CSS\\OutputFormat\:\:spaceBeforeListArgumentSeparator\(\)\.$#'
227-
identifier: method.notFound
228-
count: 1
229-
path: ../src/Value/ValueList.php
230-
23139

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 $oOutputFormat): string
5959
{
60-
$sResult = $oOutputFormat->comments($this);
60+
$formatter = $oOutputFormat->getFormatter();
61+
$sResult = $formatter->comments($this);
6162
$sResult .= $oOutputFormat->sBeforeAtRuleBlock;
6263
$sArgs = $this->sArgs;
6364
if ($sArgs) {
6465
$sArgs = ' ' . $sArgs;
6566
}
66-
$sResult .= "@{$this->type}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
67+
$sResult .= "@{$this->type}$sArgs{$formatter->spaceBeforeOpeningBrace()}{";
6768
$sResult .= $this->renderListContents($oOutputFormat);
6869
$sResult .= '}';
6970
$sResult .= $oOutputFormat->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 $oOutputFormat)
418418
if (!$this->isRootList()) {
419419
$nextLevelFormat = $oOutputFormat->nextLevel();
420420
}
421+
$nextLevelFormatter = $nextLevelFormat->getFormatter();
422+
$formatter = $oOutputFormat->getFormatter();
421423
foreach ($this->contents as $listItem) {
422-
$renderedCss = $oOutputFormat->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 .= $oOutputFormat->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
@@ -119,7 +119,7 @@ public function render(?OutputFormat $oOutputFormat = null): string
119119
if ($oOutputFormat === null) {
120120
$oOutputFormat = new OutputFormat();
121121
}
122-
return $oOutputFormat->comments($this) . $this->renderListContents($oOutputFormat);
122+
return $oOutputFormat->getFormatter()->comments($this) . $this->renderListContents($oOutputFormat);
123123
}
124124

125125
public function isRootList(): bool

src/CSSList/KeyFrame.php

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

6969
public function render(OutputFormat $oOutputFormat): string
7070
{
71-
$sResult = $oOutputFormat->comments($this);
72-
$sResult .= "@{$this->vendorKeyFrame} {$this->animationName}{$oOutputFormat->spaceBeforeOpeningBrace()}{";
71+
$formatter = $oOutputFormat->getFormatter();
72+
$sResult = $formatter->comments($this);
73+
$sResult .= "@{$this->vendorKeyFrame} {$this->animationName}{$formatter->spaceBeforeOpeningBrace()}{";
7374
$sResult .= $this->renderListContents($oOutputFormat);
7475
$sResult .= '}';
7576
return $sResult;

src/Property/Charset.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 $oOutputFormat): string
8181
{
82-
return "{$oOutputFormat->comments($this)}@charset {$this->oCharset->render($oOutputFormat)};";
82+
return "{$oOutputFormat->getFormatter()->comments($this)}@charset {$this->oCharset->render($oOutputFormat)};";
8383
}
8484

8585
public function atRuleName(): string

src/Property/Import.php

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

8181
public function render(OutputFormat $oOutputFormat): string
8282
{
83-
return $oOutputFormat->comments($this) . '@import ' . $this->location->render($oOutputFormat)
83+
return $oOutputFormat->getFormatter()->comments($this) . '@import ' . $this->location->render($oOutputFormat)
8484
. ($this->mediaQuery === null ? '' : ' ' . $this->mediaQuery) . ';';
8585
}
8686

src/Rule/Rule.php

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

270270
public function render(OutputFormat $oOutputFormat): string
271271
{
272-
$sResult = "{$oOutputFormat->comments($this)}{$this->sRule}:{$oOutputFormat->spaceAfterRuleName()}";
272+
$formatter = $oOutputFormat->getFormatter();
273+
$sResult = "{$formatter->comments($this)}{$this->sRule}:{$formatter->spaceAfterRuleName()}";
273274
if ($this->mValue instanceof Value) { // Can also be a ValueList
274275
$sResult .= $this->mValue->render($oOutputFormat);
275276
} 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 $oOutputFormat): string
6262
{
63-
$sResult = $oOutputFormat->comments($this);
63+
$formatter = $oOutputFormat->getFormatter();
64+
$sResult = $formatter->comments($this);
6465
$sArgs = $this->sArgs;
6566
if ($sArgs) {
6667
$sArgs = ' ' . $sArgs;
6768
}
68-
$sResult .= "@{$this->sType}$sArgs{$oOutputFormat->spaceBeforeOpeningBrace()}{";
69+
$sResult .= "@{$this->sType}$sArgs{$formatter->spaceBeforeOpeningBrace()}{";
6970
$sResult .= $this->renderRules($oOutputFormat);
7071
$sResult .= '}';
7172
return $sResult;

src/RuleSet/DeclarationBlock.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,21 +161,23 @@ public function __toString(): string
161161
*/
162162
public function render(OutputFormat $oOutputFormat): string
163163
{
164-
$sResult = $oOutputFormat->comments($this);
164+
$formatter = $oOutputFormat->getFormatter();
165+
$sResult = $formatter->comments($this);
165166
if (\count($this->aSelectors) === 0) {
166167
// If all the selectors have been removed, this declaration block becomes invalid
167168
throw new OutputException('Attempt to print declaration block with missing selector', $this->lineNumber);
168169
}
169170
$sResult .= $oOutputFormat->sBeforeDeclarationBlock;
170-
$sResult .= $oOutputFormat->implode(
171-
$oOutputFormat->spaceBeforeSelectorSeparator() . ',' . $oOutputFormat->spaceAfterSelectorSeparator(),
171+
$sResult .= $formatter->implode(
172+
$formatter->spaceBeforeSelectorSeparator() . ',' . $formatter->spaceAfterSelectorSeparator(),
172173
$this->aSelectors
173174
);
174175
$sResult .= $oOutputFormat->sAfterDeclarationBlockSelectors;
175-
$sResult .= $oOutputFormat->spaceBeforeOpeningBrace() . '{';
176+
$sResult .= $formatter->spaceBeforeOpeningBrace() . '{';
176177
$sResult .= $this->renderRules($oOutputFormat);
177178
$sResult .= '}';
178179
$sResult .= $oOutputFormat->sAfterDeclarationBlock;
180+
179181
return $sResult;
180182
}
181183
}

0 commit comments

Comments
 (0)