Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
77.78% covered (warning)
77.78%
7 / 9
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
Title
77.78% covered (warning)
77.78%
7 / 9
66.67% covered (warning)
66.67%
2 / 3
6.40
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
 text
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 collectText
71.43% covered (warning)
71.43%
5 / 7
0.00% covered (danger)
0.00%
0 / 1
4.37
1<?php
2
3declare(strict_types=1);
4
5namespace Phpdftk\Svg;
6
7/**
8 * SVG 2 §15.3 — `<title>` element. Accessibility-tree title for
9 * the closest container. Never renders directly. The PDF
10 * writer's tagged-PDF path uses the title to populate the
11 * structure tree's title attribute on the matching mark.
12 */
13final class Title extends Element
14{
15    public function __construct()
16    {
17        parent::__construct('title');
18    }
19
20    public function text(): string
21    {
22        return trim($this->collectText($this));
23    }
24
25    private function collectText(Element $element): string
26    {
27        $out = '';
28        foreach ($element->children as $child) {
29            if ($child instanceof Text) {
30                $out .= $child->data;
31            } elseif ($child instanceof Element) {
32                $out .= $this->collectText($child);
33            }
34        }
35        return $out;
36    }
37}