| Conditions | 4 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 11 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | 13 | public function __invoke(\DOMElement $svg, array $options = []): \DOMElement |
|
| 19 | { |
||
| 20 | 13 | if (empty($options['title'])) { |
|
| 21 | 12 | return $svg; // Do nothing unless title is set |
|
| 22 | } |
||
| 23 | |||
| 24 | /** @var \DOMNode $child */ |
||
| 25 | 4 | foreach ($svg->getElementsByTagName('title') as $child) { |
|
| 26 | // Remove title nodes directly under main element |
||
| 27 | 1 | if ($child->parentNode === $svg) { |
|
| 28 | 1 | DomUtil::removeNode($child); |
|
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | // Create title element |
||
| 33 | 4 | $title = DomUtil::createElement('title', $options['title'], $svg->firstChild, true); |
|
| 34 | |||
| 35 | // Reference title identifier with aria attribute |
||
| 36 | 4 | $title->setAttribute('id', $options['aria-labelledby']); |
|
| 37 | 4 | $svg->setAttribute('aria-labelledby', $options['aria-labelledby']); |
|
| 38 | |||
| 39 | // Remove unneeded title attribute |
||
| 40 | 4 | $svg->removeAttribute('title'); |
|
| 41 | |||
| 42 | 4 | return $svg; |
|
| 43 | } |
||
| 45 |