Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
Icon
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
100.00% covered (success)
100.00%
1 / 1
 render
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
3
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Panel;
6
7final class Icon
8{
9    public static function render(string $name): string
10    {
11        if (preg_match('/\A[a-z0-9]+(?:-[a-z0-9]+)*\z/', $name) !== 1) {
12            return '';
13        }
14
15        $path = __DIR__ . '/../../panel/icons/' . $name . '.svg';
16
17        if (!is_file($path)) {
18            return '';
19        }
20
21        return str_replace(
22            ['<svg ', 'class="bi '],
23            ['<svg aria-hidden="true" focusable="false" ', 'class="cms-icon bi '],
24            file_get_contents($path),
25        );
26    }
27}