| Total Complexity | 6 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class Helper |
||
| 9 | { |
||
| 10 | 11 | public static function getDomElements(\DOMNodeList $nodeList, ?string $nodeName): array |
|
| 11 | { |
||
| 12 | 11 | $els = array_filter(iterator_to_array($nodeList), function ($node) use ($nodeName) { |
|
| 13 | // return $node instanceof \DOMElement && ($nodeName && $node->nodeName === $nodeName); |
||
| 14 | |||
| 15 | 11 | if (! $node instanceof \DOMElement) { |
|
| 16 | 10 | return false; |
|
| 17 | } |
||
| 18 | |||
| 19 | 11 | if (! $nodeName) { |
|
| 20 | 4 | return true; |
|
| 21 | } |
||
| 22 | |||
| 23 | 7 | return $node->nodeName === $nodeName; |
|
| 24 | }); |
||
| 25 | |||
| 26 | 11 | return array_values($els); |
|
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @see https://stackoverflow.com/q/413071/2732184 |
||
| 31 | * @see https://www.regextester.com/97707 |
||
| 32 | */ |
||
| 33 | 2 | public static function translate(CacheContract $cache, string $prefix, string $text, string $pattern = '/[^{\}]+(?=})/'): string |
|
| 49 | } |
||
| 50 | } |
||
| 51 |