Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
1 / 4
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
CustomProperty
25.00% covered (danger)
25.00%
1 / 4
50.00% covered (danger)
50.00%
1 / 2
6.80
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
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * `var(--name, <fallback>)` — an unresolved reference to a custom property.
9 *
10 * Lives untouched in the value tree until the cascade resolves it: when a
11 * computed style is being built for an element, the cascade walks up the
12 * inheritance chain looking for `--name` and substitutes its value here.
13 * If no chain entry has it, the fallback is used; if there's no fallback
14 * either, the property becomes invalid at computed-value time and the
15 * cascade falls back to the initial value.
16 */
17final readonly class CustomProperty extends Value
18{
19    public function __construct(public string $name, public ?Value $fallback = null) {}
20
21    public function toCss(): string
22    {
23        if ($this->fallback !== null) {
24            return sprintf('var(%s, %s)', $this->name, $this->fallback->toCss());
25        }
26        return sprintf('var(%s)', $this->name);
27    }
28}