Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
StyleElement
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
4
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
 cssText
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg;
6
7/**
8 * SVG `<style>` per SVG 2 §6.4. The CSS source lives in the element's text
9 * children verbatim; `cssText()` concatenates them so callers don't have
10 * to walk the child list themselves.
11 *
12 * The parser deliberately does **not** parse the CSS. That happens in
13 * `Phpdftk\Svg\Css\CssBridge` (which depends on `phpdftk/css` — kept
14 * optional so the parser stays usable standalone). Sanitiser-style callers
15 * can read the raw text without pulling in a CSS parser.
16 */
17final class StyleElement extends Element
18{
19    public function __construct()
20    {
21        parent::__construct('style');
22    }
23
24    /**
25     * Concatenated CSS text from all `Text` child nodes. Whitespace is
26     * preserved exactly as it appeared in the source so source maps and
27     * line numbers stay correct.
28     */
29    public function cssText(): string
30    {
31        $out = '';
32        foreach ($this->children as $child) {
33            if ($child instanceof Text) {
34                $out .= $child->data;
35            }
36        }
37        return $out;
38    }
39}