Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StringFunction
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toCss
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Css\Value;
6
7/**
8 * CSS Generated Content for Paged Media 3 §5.2 — `string(<name>
9 * [, <fetch-target>]?)`. Returns the current value of a named
10 * string defined via `string-set`. The fetch-target keyword
11 * selects which page's value to use:
12 *
13 *   - `first`  — first assignment on the page (default).
14 *   - `start`  — value at page start (i.e. last assignment from
15 *                an earlier page, or null when nothing yet).
16 *   - `last`   — last assignment on the page.
17 *   - `first-except` — same as `first` but null if the entry
18 *                element starts on this page.
19 *
20 * The renderer resolves the value at paint time once the
21 * page-by-page string store is built up from cascade
22 * `string-set` assignments.
23 */
24final readonly class StringFunction extends Value
25{
26    public function __construct(
27        public string $name,
28        public string $target = 'first',
29    ) {}
30
31    public function toCss(): string
32    {
33        return $this->target === 'first'
34            ? sprintf('string(%s)', $this->name)
35            : sprintf('string(%s, %s)', $this->name, $this->target);
36    }
37}