Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
60.00% covered (warning)
60.00%
3 / 5
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
PaintFunction
60.00% covered (warning)
60.00%
3 / 5
50.00% covered (danger)
50.00%
1 / 2
3.58
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
50.00% covered (danger)
50.00%
2 / 4
0.00% covered (danger)
0.00%
0 / 1
2.50
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Painting API Level 1 — `paint(<name> [, <arg>]*)`.
9 * References a CSS Houdini paint worklet by name; the worklet
10 * is JS-side, so for print PDF rendering this is purely
11 * declarative preservation — the cascade keeps the call shape
12 * so external tooling can react to it, but no paint runs.
13 *
14 *   background: paint(myCheckerboard, blue, 16px);
15 */
16final readonly class PaintFunction extends Value
17{
18    /** @param list<Value> $arguments */
19    public function __construct(
20        public string $name,
21        public array $arguments = [],
22    ) {}
23
24    public function toCss(): string
25    {
26        if ($this->arguments === []) {
27            return sprintf('paint(%s)', $this->name);
28        }
29        $args = implode(', ', array_map(static fn(Value $v): string => $v->toCss(), $this->arguments));
30        return sprintf('paint(%s, %s)', $this->name, $args);
31    }
32}