Completed
Push — feature/map-redesign ( 000b6a...c361ac )
by Vladimir
26:33
created

Ionicon   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __invoke() 0 26 6
A get() 0 9 1
1
<?php
2
3
namespace BZIon\Twig;
4
5
class Ionicon
6
{
7
    private static $svgPath = '/assets/svg';
8
    private static $svgIcons = [];
9
10
    public function __invoke(\Twig_Environment $env, $name, $height = null, $width = null)
11
    {
12
        $svg = DOC_ROOT . self::$svgPath . '/' . $name . '.svg';
13
14
        if (isset(self::$svgIcons[$name])) {
15
            return self::$svgIcons[$name];
16
        }
17
18
        if (file_exists($svg)) {
19
            $svgDoc = simplexml_load_string(file_get_contents($svg));
20
21
            if ($svgDoc === false) {
22
                return '';
23
            }
24
25
            $svgDoc->addAttribute('class', 'ionicon');
26
            $height && $svgDoc->addAttribute('height', $height);
27
            $width  && $svgDoc->addAttribute('width', $width);
28
29
            self::$svgIcons[$name] = $svgDoc->asXML();
30
31
            return self::$svgIcons[$name];
32
        }
33
34
        return '';
35
    }
36
37
    public static function get()
38
    {
39
        return new \Twig_SimpleFunction('ionicon', new self(), [
40
            'needs_environment' => true,
41
            'is_safe' => [
42
                'evaluate' => true
43
            ]
44
        ]);
45
    }
46
}
47