Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
90.91% covered (success)
90.91%
10 / 11
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
LinearGradient
90.91% covered (success)
90.91%
10 / 11
83.33% covered (warning)
83.33%
5 / 6
8.05
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
 x1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 y1
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 x2
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 y2
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 parseOptionalLength
83.33% covered (warning)
83.33%
5 / 6
0.00% covered (danger)
0.00%
0 / 1
3.04
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Gradient;
6
7/**
8 * SVG `<linearGradient>` per SVG 2 §13.6. Endpoints `(x1, y1)` and
9 * `(x2, y2)` define the gradient axis; stops are colour samples along it.
10 *
11 * Each endpoint accessor returns null when the attribute is absent so the
12 * painter can apply the unit-mode-specific defaults (e.g., `x1=0` /
13 * `x2=1` in `objectBoundingBox` mode, `0` / `100%` in `userSpaceOnUse`
14 * mode per SVG 2 §13.6.5).
15 */
16final class LinearGradient extends Gradient
17{
18    public function __construct()
19    {
20        parent::__construct('linearGradient');
21    }
22
23    public function x1(): ?float
24    {
25        return $this->parseOptionalLength('x1');
26    }
27
28    public function y1(): ?float
29    {
30        return $this->parseOptionalLength('y1');
31    }
32
33    public function x2(): ?float
34    {
35        return $this->parseOptionalLength('x2');
36    }
37
38    public function y2(): ?float
39    {
40        return $this->parseOptionalLength('y2');
41    }
42
43    private function parseOptionalLength(string $attr): ?float
44    {
45        $raw = $this->getAttribute($attr);
46        if ($raw === null) {
47            return null;
48        }
49        if (preg_match('/^\s*([+-]?(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?)/', $raw, $m) !== 1) {
50            return null;
51        }
52        return (float) $m[1];
53    }
54}