Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
25.00% covered (danger)
25.00%
3 / 12
50.00% covered (danger)
50.00%
3 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
FeSpecularLighting
25.00% covered (danger)
25.00%
3 / 12
50.00% covered (danger)
50.00%
3 / 6
43.17
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
 lightingColor
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 surfaceScale
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 specularConstant
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 specularExponent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 kernelUnitLength
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg\Filter;
6
7/**
8 * SVG 2 Filter Effects §15.15 — `<feSpecularLighting>`. Same
9 * surface-from-alpha model as feDiffuseLighting, but with the
10 * Phong specular reflection model.
11 *
12 *   lighting-color / surfaceScale / kernelUnitLength
13 *     — same as feDiffuseLighting.
14 *   specularConstant:  Phong coefficient ks, default 1
15 *   specularExponent:  Phong shininess exponent, default 1
16 */
17final class FeSpecularLighting extends FilterPrimitive
18{
19    public function __construct()
20    {
21        parent::__construct('feSpecularLighting');
22    }
23
24    public function lightingColor(): string
25    {
26        return $this->getAttribute('lighting-color') ?? 'white';
27    }
28
29    public function surfaceScale(): float
30    {
31        return (float) ($this->getAttribute('surfaceScale') ?? 1);
32    }
33
34    public function specularConstant(): float
35    {
36        return max(0.0, (float) ($this->getAttribute('specularConstant') ?? 1));
37    }
38
39    public function specularExponent(): float
40    {
41        return max(1.0, (float) ($this->getAttribute('specularExponent') ?? 1));
42    }
43
44    /**
45     * @return array{0: float, 1: float}|null
46     */
47    public function kernelUnitLength(): ?array
48    {
49        $raw = trim($this->getAttribute('kernelUnitLength') ?? '');
50        if ($raw === '') {
51            return null;
52        }
53        $parts = preg_split('/[\s,]+/', $raw) ?: [];
54        $dx = max(0.0, (float) ($parts[0] ?? 1));
55        $dy = isset($parts[1]) ? max(0.0, (float) $parts[1]) : $dx;
56        return [$dx, $dy];
57    }
58}