Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
Path
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
3 / 3
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
 dRaw
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 d
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg;
6
7use Phpdftk\Svg\Path\PathData;
8
9/**
10 * SVG `<path>` element per SVG 2 §9. The geometry lives in the `d` attribute;
11 * call `d()` to get a typed `PathData` AST or `dRaw()` for the original
12 * string (round-tripping, diagnostics).
13 */
14final class Path extends Element
15{
16    public function __construct()
17    {
18        parent::__construct('path');
19    }
20
21    /**
22     * The original `d` attribute value, verbatim. Useful for sanitiser-style
23     * workflows that want to compare or re-emit without parsing.
24     */
25    public function dRaw(): ?string
26    {
27        return $this->getAttribute('d');
28    }
29
30    /**
31     * Parsed `d` attribute. Always returns a `PathData` — an absent or
32     * malformed attribute resolves to an empty command list (the spec
33     * accumulates commands up to the first error).
34     */
35    public function d(): PathData
36    {
37        $raw = $this->getAttribute('d');
38        if ($raw === null) {
39            return new PathData([]);
40        }
41        return PathData::parse($raw);
42    }
43}