Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
77.78% |
7 / 9 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Desc | |
77.78% |
7 / 9 |
|
66.67% |
2 / 3 |
6.40 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| text | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| collectText | |
71.43% |
5 / 7 |
|
0.00% |
0 / 1 |
4.37 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Phpdftk\Svg; |
| 6 | |
| 7 | /** |
| 8 | * SVG 2 §15.3 — `<desc>` element. Long-form description of the |
| 9 | * containing SVG fragment. Like `<title>`, never renders directly |
| 10 | * — purely accessibility metadata. |
| 11 | */ |
| 12 | final class Desc extends Element |
| 13 | { |
| 14 | public function __construct() |
| 15 | { |
| 16 | parent::__construct('desc'); |
| 17 | } |
| 18 | |
| 19 | public function text(): string |
| 20 | { |
| 21 | return trim($this->collectText($this)); |
| 22 | } |
| 23 | |
| 24 | private function collectText(Element $element): string |
| 25 | { |
| 26 | $out = ''; |
| 27 | foreach ($element->children as $child) { |
| 28 | if ($child instanceof Text) { |
| 29 | $out .= $child->data; |
| 30 | } elseif ($child instanceof Element) { |
| 31 | $out .= $this->collectText($child); |
| 32 | } |
| 33 | } |
| 34 | return $out; |
| 35 | } |
| 36 | } |