From 28c3f16a5d74d29c166aae69a78def6d20288928 Mon Sep 17 00:00:00 2001 From: Jake Hotson Date: Tue, 23 Dec 2025 01:14:25 +0000 Subject: [PATCH] [TASK] Add `getArrayRepresentation()` to `Renderable` 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. --- src/CSSList/CSSList.php | 10 ++++++++++ src/Comment/Comment.php | 10 ++++++++++ src/Property/CSSNamespace.php | 10 ++++++++++ src/Property/Charset.php | 10 ++++++++++ src/Property/Import.php | 10 ++++++++++ src/Property/Selector.php | 10 ++++++++++ src/Renderable.php | 7 +++++++ src/Rule/Rule.php | 10 ++++++++++ src/RuleSet/DeclarationBlock.php | 10 ++++++++++ src/RuleSet/RuleSet.php | 10 ++++++++++ src/Value/Value.php | 10 ++++++++++ tests/Unit/CSSList/CSSListTest.php | 12 ++++++++++++ tests/Unit/Comment/CommentTest.php | 12 ++++++++++++ tests/Unit/Property/CSSNamespaceTest.php | 10 ++++++++++ tests/Unit/Property/CharsetTest.php | 10 ++++++++++ tests/Unit/Property/ImportTest.php | 10 ++++++++++ tests/Unit/Property/SelectorTest.php | 12 ++++++++++++ tests/Unit/Rule/RuleTest.php | 12 ++++++++++++ tests/Unit/RuleSet/DeclarationBlockTest.php | 10 ++++++++++ tests/Unit/RuleSet/RuleSetTest.php | 10 ++++++++++ tests/Unit/Value/ValueTest.php | 12 ++++++++++++ 21 files changed, 217 insertions(+) diff --git a/src/CSSList/CSSList.php b/src/CSSList/CSSList.php index f18cd7725..7d4c7efae 100644 --- a/src/CSSList/CSSList.php +++ b/src/CSSList/CSSList.php @@ -435,6 +435,16 @@ public function getContents(): array return $this->contents; } + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } + /** * @param list $selectors1 * @param list $selectors2 diff --git a/src/Comment/Comment.php b/src/Comment/Comment.php index 6f29682c2..e09b033b6 100644 --- a/src/Comment/Comment.php +++ b/src/Comment/Comment.php @@ -46,4 +46,14 @@ public function render(OutputFormat $outputFormat): string { return '/*' . $this->commentText . '*/'; } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/Property/CSSNamespace.php b/src/Property/CSSNamespace.php index 66164a318..cb96d78ba 100644 --- a/src/Property/CSSNamespace.php +++ b/src/Property/CSSNamespace.php @@ -94,4 +94,14 @@ public function atRuleArgs(): array } return $result; } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/Property/Charset.php b/src/Property/Charset.php index c9488ad1e..9f2ae0500 100644 --- a/src/Property/Charset.php +++ b/src/Property/Charset.php @@ -71,4 +71,14 @@ public function atRuleArgs(): CSSString { return $this->charset; } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/Property/Import.php b/src/Property/Import.php index a9dabe979..366042481 100644 --- a/src/Property/Import.php +++ b/src/Property/Import.php @@ -82,4 +82,14 @@ public function getMediaQuery(): ?string { return $this->mediaQuery; } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/Property/Selector.php b/src/Property/Selector.php index b935b2a82..093f2bcf4 100644 --- a/src/Property/Selector.php +++ b/src/Property/Selector.php @@ -95,4 +95,14 @@ public function render(OutputFormat $outputFormat): string { return $this->getSelector(); } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/Renderable.php b/src/Renderable.php index 9ebf9a9b9..1385abd92 100644 --- a/src/Renderable.php +++ b/src/Renderable.php @@ -7,4 +7,11 @@ interface Renderable { public function render(OutputFormat $outputFormat): string; + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array; } diff --git a/src/Rule/Rule.php b/src/Rule/Rule.php index 96ef1b4da..c43cb414b 100644 --- a/src/Rule/Rule.php +++ b/src/Rule/Rule.php @@ -197,4 +197,14 @@ public function render(OutputFormat $outputFormat): string $result .= ';'; return $result; } + + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } } diff --git a/src/RuleSet/DeclarationBlock.php b/src/RuleSet/DeclarationBlock.php index a3921815f..386d7651c 100644 --- a/src/RuleSet/DeclarationBlock.php +++ b/src/RuleSet/DeclarationBlock.php @@ -273,6 +273,16 @@ public function render(OutputFormat $outputFormat): string return $result; } + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } + /** * @param list $comments * diff --git a/src/RuleSet/RuleSet.php b/src/RuleSet/RuleSet.php index 521a6ae9b..64bd8c4db 100644 --- a/src/RuleSet/RuleSet.php +++ b/src/RuleSet/RuleSet.php @@ -331,6 +331,16 @@ protected function renderRules(OutputFormat $outputFormat): string return $formatter->removeLastSemicolon($result); } + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } + /** * @return int negative if `$first` is before `$second`; zero if they have the same position; positive otherwise * diff --git a/src/Value/Value.php b/src/Value/Value.php index 263c420da..59c49c85f 100644 --- a/src/Value/Value.php +++ b/src/Value/Value.php @@ -181,6 +181,16 @@ public static function parsePrimitiveValue(ParserState $parserState) return $value; } + /** + * @internal + * + * @return array>> + */ + public function getArrayRepresentation(): array + { + throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`'); + } + /** * @throws UnexpectedEOFException * @throws UnexpectedTokenException diff --git a/tests/Unit/CSSList/CSSListTest.php b/tests/Unit/CSSList/CSSListTest.php index 548acbb77..3ab8d19f1 100644 --- a/tests/Unit/CSSList/CSSListTest.php +++ b/tests/Unit/CSSList/CSSListTest.php @@ -380,4 +380,16 @@ public function parseListAtRootLevelSkipsErroneousClosingBraceAndParsesFollowing self::assertSame($followingContent, $subject->render(new OutputFormat())); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $subject = new ConcreteCSSList(); + + $subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Comment/CommentTest.php b/tests/Unit/Comment/CommentTest.php index 69572e903..841420825 100644 --- a/tests/Unit/Comment/CommentTest.php +++ b/tests/Unit/Comment/CommentTest.php @@ -77,4 +77,16 @@ public function getLineNumberReturnsLineNumberProvidedToConstructor(): void self::assertSame($lineNumber, $subject->getLineNumber()); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $subject = new Comment(); + + $subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Property/CSSNamespaceTest.php b/tests/Unit/Property/CSSNamespaceTest.php index 2e4d99222..44f5c7d1f 100644 --- a/tests/Unit/Property/CSSNamespaceTest.php +++ b/tests/Unit/Property/CSSNamespaceTest.php @@ -31,4 +31,14 @@ public function implementsCSSListItem(): void { self::assertInstanceOf(CSSListItem::class, $this->subject); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $this->subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Property/CharsetTest.php b/tests/Unit/Property/CharsetTest.php index e0645f5ef..6f8fa60d6 100644 --- a/tests/Unit/Property/CharsetTest.php +++ b/tests/Unit/Property/CharsetTest.php @@ -31,4 +31,14 @@ public function implementsCSSListItem(): void { self::assertInstanceOf(CSSListItem::class, $this->subject); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $this->subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Property/ImportTest.php b/tests/Unit/Property/ImportTest.php index 4ec028e3f..3164bc201 100644 --- a/tests/Unit/Property/ImportTest.php +++ b/tests/Unit/Property/ImportTest.php @@ -32,4 +32,14 @@ public function implementsCSSListItem(): void { self::assertInstanceOf(CSSListItem::class, $this->subject); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $this->subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Property/SelectorTest.php b/tests/Unit/Property/SelectorTest.php index cfec36fba..3aca38515 100644 --- a/tests/Unit/Property/SelectorTest.php +++ b/tests/Unit/Property/SelectorTest.php @@ -188,4 +188,16 @@ public function doesNotCleanupSpacesWithinAttributeSelector(): void self::assertSame('a[title="extra space"]', $subject->getSelector()); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $subject = new Selector('a'); + + $subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Rule/RuleTest.php b/tests/Unit/Rule/RuleTest.php index 008bcfc18..3a00bd751 100644 --- a/tests/Unit/Rule/RuleTest.php +++ b/tests/Unit/Rule/RuleTest.php @@ -70,4 +70,16 @@ static function ($component): string { self::assertSame($expectedTypeClassnames, $actualClassnames); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $subject = new Rule('todo'); + + $subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/RuleSet/DeclarationBlockTest.php b/tests/Unit/RuleSet/DeclarationBlockTest.php index 980ea4004..b9c908b49 100644 --- a/tests/Unit/RuleSet/DeclarationBlockTest.php +++ b/tests/Unit/RuleSet/DeclarationBlockTest.php @@ -535,6 +535,16 @@ public function setSelectorsThrowsExceptionWithInvalidSelector(string $selector) $subject->setSelectors($selector); } + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $this->subject->getArrayRepresentation(); + } + /** * @return list */ diff --git a/tests/Unit/RuleSet/RuleSetTest.php b/tests/Unit/RuleSet/RuleSetTest.php index 92c056ca0..76cf7b2e6 100644 --- a/tests/Unit/RuleSet/RuleSetTest.php +++ b/tests/Unit/RuleSet/RuleSetTest.php @@ -79,4 +79,14 @@ public function getLineNumberReturnsLineNumberPassedToConstructor(?int $lineNumb self::assertSame($lineNumber, $result); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $this->subject->getArrayRepresentation(); + } } diff --git a/tests/Unit/Value/ValueTest.php b/tests/Unit/Value/ValueTest.php index b7279c6e9..87c282c01 100644 --- a/tests/Unit/Value/ValueTest.php +++ b/tests/Unit/Value/ValueTest.php @@ -141,4 +141,16 @@ public function parsesArithmeticWithMalformedOperandsInFunctions(string $leftOpe $subject->render(OutputFormat::createCompact()) ); } + + /** + * @test + */ + public function getArrayRepresentationThrowsException(): void + { + $this->expectException(\BadMethodCallException::class); + + $subject = new ConcreteValue(); + + $subject->getArrayRepresentation(); + } }