Skip to content

Commit 95263d1

Browse files
authored
[TASK] Implement CSSFunction::getArrayRepresentation() (#1458)
Move exception-throwing stubs down the chain to be implemented IDC. Part of #1440.
1 parent 09adec3 commit 95263d1

4 files changed

Lines changed: 42 additions & 4 deletions

File tree

src/Value/CSSFunction.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ public function render(OutputFormat $outputFormat): string
121121
*/
122122
public function getArrayRepresentation(): array
123123
{
124-
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
124+
$result = parent::getArrayRepresentation();
125+
126+
$result['name'] = $this->name;
127+
128+
return $result;
125129
}
126130
}

src/Value/CalcFunction.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,14 @@ public static function parse(ParserState $parserState, bool $ignoreCase = false)
9696
}
9797
return new CalcFunction($function, $list, ',', $parserState->currentLine());
9898
}
99+
100+
/**
101+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
102+
*
103+
* @internal
104+
*/
105+
public function getArrayRepresentation(): array
106+
{
107+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
108+
}
99109
}

src/Value/Color.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ public function render(OutputFormat $outputFormat): string
239239
return parent::render($outputFormat);
240240
}
241241

242+
/**
243+
* @return array<string, bool|int|float|string|list<array<string, mixed>>>
244+
*
245+
* @internal
246+
*/
247+
public function getArrayRepresentation(): array
248+
{
249+
throw new \BadMethodCallException('`getArrayRepresentation` is not yet implemented for `' . self::class . '`');
250+
}
251+
242252
private function shouldRenderAsHex(OutputFormat $outputFormat): bool
243253
{
244254
return

tests/Unit/Value/CSSFunctionTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,26 @@ final class CSSFunctionTest extends TestCase
1717
/**
1818
* @test
1919
*/
20-
public function getArrayRepresentationThrowsException(): void
20+
public function getArrayRepresentationIncludesClassName(): void
2121
{
22-
$this->expectException(\BadMethodCallException::class);
22+
$subject = new CSSFunction('filter', []);
23+
24+
$result = $subject->getArrayRepresentation();
2325

26+
self::assertArrayHasKey('class', $result);
27+
self::assertSame('CSSFunction', $result['class']);
28+
}
29+
30+
/**
31+
* @test
32+
*/
33+
public function getArrayRepresentationIncludesFunctionName(): void
34+
{
2435
$subject = new CSSFunction('filter', []);
2536

26-
$subject->getArrayRepresentation();
37+
$result = $subject->getArrayRepresentation();
38+
39+
self::assertArrayHasKey('name', $result);
40+
self::assertSame('filter', $result['name']);
2741
}
2842
}

0 commit comments

Comments
 (0)