Skip to content

Commit b74a000

Browse files
authored
[TASK] Add getArrayRepresentation() to Renderable (#1447)
This method will make it easier to test the parsing independently of the rendering. Placeholder implementations are currently all stubs that will throw an exception, confirmed by tests. They can be implemented as and when required, with the tests updated. Part of #1440.
1 parent 0ae1fde commit b74a000

21 files changed

Lines changed: 217 additions & 0 deletions

src/CSSList/CSSList.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,16 @@ public function getContents(): array
435435
return $this->contents;
436436
}
437437

438+
/**
439+
* @internal
440+
*
441+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
442+
*/
443+
public function getArrayRepresentation(): array
444+
{
445+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
446+
}
447+
438448
/**
439449
* @param list<Selector> $selectors1
440450
* @param list<Selector> $selectors2

src/Comment/Comment.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,14 @@ public function render(OutputFormat $outputFormat): string
4646
{
4747
return '/*' . $this->commentText . '*/';
4848
}
49+
50+
/**
51+
* @internal
52+
*
53+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
54+
*/
55+
public function getArrayRepresentation(): array
56+
{
57+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
58+
}
4959
}

src/Property/CSSNamespace.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,14 @@ public function atRuleArgs(): array
9494
}
9595
return $result;
9696
}
97+
98+
/**
99+
* @internal
100+
*
101+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
102+
*/
103+
public function getArrayRepresentation(): array
104+
{
105+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
106+
}
97107
}

src/Property/Charset.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,14 @@ public function atRuleArgs(): CSSString
7171
{
7272
return $this->charset;
7373
}
74+
75+
/**
76+
* @internal
77+
*
78+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
79+
*/
80+
public function getArrayRepresentation(): array
81+
{
82+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
83+
}
7484
}

src/Property/Import.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,14 @@ public function getMediaQuery(): ?string
8282
{
8383
return $this->mediaQuery;
8484
}
85+
86+
/**
87+
* @internal
88+
*
89+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
90+
*/
91+
public function getArrayRepresentation(): array
92+
{
93+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
94+
}
8595
}

src/Property/Selector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,14 @@ public function render(OutputFormat $outputFormat): string
9595
{
9696
return $this->getSelector();
9797
}
98+
99+
/**
100+
* @internal
101+
*
102+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
103+
*/
104+
public function getArrayRepresentation(): array
105+
{
106+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
107+
}
98108
}

src/Renderable.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,11 @@
77
interface Renderable
88
{
99
public function render(OutputFormat $outputFormat): string;
10+
11+
/**
12+
* @internal
13+
*
14+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
15+
*/
16+
public function getArrayRepresentation(): array;
1017
}

src/Rule/Rule.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,14 @@ public function render(OutputFormat $outputFormat): string
197197
$result .= ';';
198198
return $result;
199199
}
200+
201+
/**
202+
* @internal
203+
*
204+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
205+
*/
206+
public function getArrayRepresentation(): array
207+
{
208+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
209+
}
200210
}

src/RuleSet/DeclarationBlock.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,16 @@ public function render(OutputFormat $outputFormat): string
273273
return $result;
274274
}
275275

276+
/**
277+
* @internal
278+
*
279+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
280+
*/
281+
public function getArrayRepresentation(): array
282+
{
283+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
284+
}
285+
276286
/**
277287
* @param list<Comment> $comments
278288
*

src/RuleSet/RuleSet.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,16 @@ protected function renderRules(OutputFormat $outputFormat): string
331331
return $formatter->removeLastSemicolon($result);
332332
}
333333

334+
/**
335+
* @internal
336+
*
337+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
338+
*/
339+
public function getArrayRepresentation(): array
340+
{
341+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
342+
}
343+
334344
/**
335345
* @return int negative if `$first` is before `$second`; zero if they have the same position; positive otherwise
336346
*

0 commit comments

Comments
 (0)