Skip to content

Commit 416f6a7

Browse files
authored
[TASK] Implement Value::getArrayRepresentation() (#1480)
This implementation might get removed if all subclasses have their own implementation without needing the parent class implementation. Part of #1440.
1 parent 6455dd1 commit 416f6a7

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/Value/Value.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Sabberworm\CSS\Parsing\UnexpectedTokenException;
1212
use Sabberworm\CSS\Position\Position;
1313
use Sabberworm\CSS\Position\Positionable;
14+
use Sabberworm\CSS\ShortClassNameProvider;
1415

1516
use function Safe\preg_match;
1617

@@ -21,6 +22,7 @@
2122
abstract class Value implements CSSElement, Positionable
2223
{
2324
use Position;
25+
use ShortClassNameProvider;
2426

2527
/**
2628
* @param int<1, max>|null $lineNumber
@@ -188,9 +190,9 @@ public static function parsePrimitiveValue(ParserState $parserState)
188190
*/
189191
public function getArrayRepresentation(): array
190192
{
191-
throw new \BadMethodCallException(
192-
'`getArrayRepresentation` is not yet implemented for `' . static::class . '`'
193-
);
193+
return [
194+
'class' => $this->getShortClassName(),
195+
];
194196
}
195197

196198
/**

tests/Unit/Value/ValueTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,12 @@ public function parsesArithmeticWithMalformedOperandsInFunctions(string $leftOpe
179179
/**
180180
* @test
181181
*/
182-
public function getArrayRepresentationThrowsException(): void
182+
public function getArrayRepresentationIncludesClassName(): void
183183
{
184-
$this->expectException(\BadMethodCallException::class);
185-
186184
$subject = new ConcreteValue();
187185

188-
$subject->getArrayRepresentation();
186+
$result = $subject->getArrayRepresentation();
187+
188+
self::assertSame('ConcreteValue', $result['class']);
189189
}
190190
}

0 commit comments

Comments
 (0)