Passed
Push — master ( 6f581c...a35795 )
by Revin
02:43
created

Stack::on()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 10
loc 10
c 0
b 0
f 0
ccs 0
cts 8
cp 0
rs 9.9332
cc 2
nc 2
nop 2
crap 6
1
<?php
2
/**
3
 * Stack.php
4
 * @author Revin Roman
5
 * @link https://rmrevin.ru
6
 */
7
8
namespace rmrevin\yii\fontawesome\component;
9
10
use rmrevin\yii\fontawesome\FontAwesome;
11
use yii\helpers\ArrayHelper;
12
use yii\helpers\Html;
13
14
/**
15
 * Class Stack
16
 * @package rmrevin\yii\fontawesome\component
17
 */
18
class Stack
19
{
20
    /**
21
     * @var string
22
     */
23
    private $iconCssPrefix = 'fa';
24
25
    /**
26
     * @var array
27
     */
28
    private $options = [];
29
30
    /**
31
     * @var Icon
32
     */
33
    private $icon_front;
34
35
    /**
36
     * @var Icon
37
     */
38
    private $icon_back;
39
40
    /**
41
     * @param string $iconCssPrefix
42
     * @param array $options
43
     */
44
    public function __construct($iconCssPrefix, $options = [])
45
    {
46
        $this->iconCssPrefix = $iconCssPrefix;
47
48
        Html::addCssClass($options, FontAwesome::$basePrefix . '-stack');
49
50
        $this->options = $options;
51
    }
52
53
    /**
54
     * @return string
55
     * @throws \yii\base\InvalidConfigException
56
     */
57
    public function __toString()
58
    {
59
        $options = $this->options;
60
61
        $tag = ArrayHelper::remove($options, 'tag', 'span');
62
63
        $template = ArrayHelper::remove($options, 'template', '{back}{front}');
64
65
        $icon_back = $this->icon_back instanceof Icon
66
            ? $this->icon_back->addCssClass(FontAwesome::$basePrefix . '-stack-2x')
67
            : null;
68
69
        $icon_front = $this->icon_front instanceof Icon
70
            ? $this->icon_front->addCssClass(FontAwesome::$basePrefix . '-stack-1x')
71
            : null;
72
73
        $content = str_replace(['{back}', '{front}'], [$icon_back, $icon_front], $template);
74
75
        return Html::tag($tag, $content, $options);
76
    }
77
78
    /**
79
     * @param string|Icon $icon
80
     * @param array $options
81
     * @return \rmrevin\yii\fontawesome\component\Stack
82
     */
83 View Code Duplication
    public function icon($icon, $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
84
    {
85
        if (is_string($icon)) {
86
            $icon = new Icon($this->iconCssPrefix, $icon, $options);
87
        }
88
89
        $this->icon_front = $icon;
90
91
        return $this;
92
    }
93
94
    /**
95
     * @param string|Icon $icon
96
     * @param array $options
97
     * @return \rmrevin\yii\fontawesome\component\Stack
98
     */
99 View Code Duplication
    public function on($icon, $options = [])
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
    {
101
        if (is_string($icon)) {
102
            $icon = new Icon($this->iconCssPrefix, $icon, $options);
103
        }
104
105
        $this->icon_back = $icon;
106
107
        return $this;
108
    }
109
}
110