Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
Icon
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
4.01
0.00% covered (danger)
0.00%
0 / 1
 render
92.31% covered (success)
92.31%
12 / 13
0.00% covered (danger)
0.00%
0 / 1
4.01
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        $svg = file_get_contents($path);
22
23        if ($svg === false) {
24            return '';
25        }
26
27        return str_replace(
28            ['<svg ', 'class="bi '],
29            ['<svg aria-hidden="true" focusable="false" ', 'class="cms-icon bi '],
30            $svg,
31        );
32    }
33}