Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.67% covered (warning)
86.67%
13 / 15
71.43% covered (warning)
71.43%
5 / 7
CRAP
0.00% covered (danger)
0.00%
0 / 1
Rect
86.67% covered (warning)
86.67%
13 / 15
71.43% covered (warning)
71.43%
5 / 7
11.29
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
 x
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 y
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 width
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 height
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rx
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
 ry
80.00% covered (warning)
80.00%
4 / 5
0.00% covered (danger)
0.00%
0 / 1
3.07
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Shape;
6
7use Phpdftk\Svg\Element;
8
9/**
10 * SVG `<rect>` element per SVG 2 ยง10.4. Stores attributes as raw strings
11 * and parses them on demand โ€” see `x()` / `y()` / `width()` / `height()`
12 * / `rx()` / `ry()` for the typed accessors.
13 *
14 * Length parsing keeps the value + unit; unitless numbers (the common case
15 * for `viewBox`-relative content) come back as a float with `unit = null`.
16 */
17final class Rect extends Element
18{
19    public function __construct()
20    {
21        parent::__construct('rect');
22    }
23
24    /** `x` attribute parsed as length; null/missing โ†’ 0 per spec. */
25    public function x(): float
26    {
27        return $this->parseLengthOrZero('x');
28    }
29
30    /** `y` attribute parsed as length; null/missing โ†’ 0 per spec. */
31    public function y(): float
32    {
33        return $this->parseLengthOrZero('y');
34    }
35
36    public function width(): float
37    {
38        return $this->parseLengthOrZero('width');
39    }
40
41    public function height(): float
42    {
43        return $this->parseLengthOrZero('height');
44    }
45
46    /**
47     * `rx` (corner-radius x). Returns null when neither `rx` nor `ry` is
48     * set so the caller can distinguish "no rounding" from "rounded with
49     * radius 0" โ€” semantically the same paint, but useful for downstream
50     * code that wants to preserve the author's intent.
51     */
52    public function rx(): ?float
53    {
54        if ($this->hasAttribute('rx')) {
55            return $this->parseLengthOrZero('rx');
56        }
57        if ($this->hasAttribute('ry')) {
58            return $this->parseLengthOrZero('ry');
59        }
60        return null;
61    }
62
63    public function ry(): ?float
64    {
65        if ($this->hasAttribute('ry')) {
66            return $this->parseLengthOrZero('ry');
67        }
68        if ($this->hasAttribute('rx')) {
69            return $this->parseLengthOrZero('rx');
70        }
71        return null;
72    }
73}