Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
86.67% covered (warning)
86.67%
13 / 15
66.67% covered (warning)
66.67%
4 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeDropShadow
86.67% covered (warning)
86.67%
13 / 15
66.67% covered (warning)
66.67%
4 / 6
10.24
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
 dx
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 dy
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 stdDeviation
85.71% covered (warning)
85.71%
6 / 7
0.00% covered (danger)
0.00%
0 / 1
4.05
 floodColor
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 floodOpacity
75.00% covered (warning)
75.00%
3 / 4
0.00% covered (danger)
0.00%
0 / 1
2.06
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Filter;
6
7/**
8 * SVG 2 Filter Effects §15.18 — `<feDropShadow>`. A composite
9 * primitive equivalent to the canonical "feOffset + feGaussian-
10 * Blur + feFlood + feComposite + feMerge" drop-shadow chain.
11 *
12 *   <feDropShadow dx="2" dy="2" stdDeviation="3"
13 *                 flood-color="black" flood-opacity="0.5"/>
14 */
15final class FeDropShadow extends FilterPrimitive
16{
17    public function __construct()
18    {
19        parent::__construct('feDropShadow');
20    }
21
22    public function dx(): float
23    {
24        return (float) ($this->getAttribute('dx') ?? 2);
25    }
26
27    public function dy(): float
28    {
29        return (float) ($this->getAttribute('dy') ?? 2);
30    }
31
32    /**
33     * @return array{0: float, 1: float}  [sigmaX, sigmaY]
34     */
35    public function stdDeviation(): array
36    {
37        $raw = trim($this->getAttribute('stdDeviation') ?? '');
38        if ($raw === '') {
39            return [2.0, 2.0];
40        }
41        $parts = preg_split('/[\s,]+/', $raw) ?: [];
42        $sx = max(0.0, (float) ($parts[0] ?? 0));
43        $sy = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $sx;
44        return [$sx, $sy];
45    }
46
47    public function floodColor(): string
48    {
49        return $this->getAttribute('flood-color') ?? 'black';
50    }
51
52    public function floodOpacity(): float
53    {
54        $v = $this->getAttribute('flood-opacity');
55        if ($v === null) {
56            return 1.0;
57        }
58        return max(0.0, min(1.0, (float) $v));
59    }
60}