Passed
Push — master ( 58d826...5004b9 )
by Mr.
01:49
created

Icon::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace YiiRocks\SvgInline;
6
7
/**
8
 * Icon class to store all icon properties.
9
 */
10
class Icon implements IconInterface
11
{
12
    /** @var string Additional custom classes */
13
    private string $class;
14
15
    /** @var array Additional CSS attributes */
16
    private array $css;
17
18
    /** @var string Color of the icon. Set to empty string to disable this attribute */
19
    private string $fill;
20
21
    /**
22
     * @var int The height of the icon. This will dismiss the automatic height
23
     *          and width classes. If height is given without width, the latter
24
     *          will be calculated from the SVG size
25
     */
26
    private int $height;
27
28
    /**
29
     * @var string Id for the SVG tag.
30
     */
31
    private string $id;
32
33
    /**
34
     * @var string Valid path to an SVG image
35
     */
36
    private string $name;
37
38
    /** @var null|string Sets a title to the SVG output */
39
    private ?string $title;
40
41
    /**
42
     * @var int The width of the icon. This will dismiss the automatic height
43
     *          and width classes. If `width` is given without `height`, the
44
     *          latter will be calculated from the SVG size
45
     */
46
    private int $width;
47
48
    public function __construct()
49
    {
50
        $this->title = null;
51
    }
52
53
    /**
54
     * @see $icon
55
     * @param string $key
56
     * @return mixed
57
     */
58
    public function get(string $key)
59
    {
60
        return $this->$key ?? null;
61
    }
62
63
    /**
64
     * @see $name
65
     * @return string
66
     */
67
    public function getTitle(): string
68
    {
69
        return $this->title ?? basename($this->name, '.svg');
70
    }
71
72
    public function setClass(string $value): void
73
    {
74
        $this->class = $value;
75
    }
76
77
    public function setCss(array $value): void
78
    {
79
        $this->css = $value;
80
    }
81
82
    public function setFill(string $value): void
83
    {
84
        $this->fill = $value;
85
    }
86
87
    public function setHeight(int $value): void
88
    {
89
        $this->height = abs($value);
90
    }
91
92
    public function setId(string $value): void
93
    {
94
        $this->id = $value;
95
    }
96
97
    public function setName(string $value): void
98
    {
99
        $this->name = $value;
100
    }
101
102
    public function setTitle(string $value): void
103
    {
104
        $this->title = $value;
105
    }
106
107
    public function setWidth(int $value): void
108
    {
109
        $this->width = abs($value);
110
    }
111
}
112