Passed
Push — master ( 65ce30...1d3ad7 )
by Revin
02:45
created

Icon::pulse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * Icon.php
4
 * @author Revin Roman
5
 * @link https://rmrevin.ru
6
 */
7
8
namespace rmrevin\yii\fontawesome\component;
9
10
use rmrevin\yii\fontawesome\FA;
11
use yii\helpers\ArrayHelper;
12
use yii\helpers\Html;
13
14
/**
15
 * Class Icon
16
 * @package rmrevin\yii\fontawesome\component
17
 */
18
class Icon
19
{
20
21
    /**
22
     * @deprecated
23
     * @var string
24
     */
25
    public static $defaultTag = 'i';
26
27
    /**
28
     * @deprecated
29
     * @var string
30
     */
31
    private $tag;
32
33
    /**
34
     * @var array
35
     */
36
    private $options = [];
37
38
    /**
39
     * @param string $name
40
     * @param array $options
41
     */
42 10
    public function __construct($name, $options = [])
43
    {
44 10
        Html::addCssClass($options, FA::$cssPrefix);
45
46 10
        if (!empty($name)) {
47 10
            Html::addCssClass($options, FA::$cssPrefix . '-' . $name);
48 10
        }
49
50 10
        $this->options = $options;
51 10
    }
52
53
    /**
54
     * @return string
55
     */
56 6
    public function __toString()
57
    {
58 6
        $options = $this->options;
59
60 6
        $tag = ArrayHelper::remove($options, 'tag', 'i');
61
62 6
        return Html::tag($tag, null, $options);
63
    }
64
65
    /**
66
     * @return self
67
     */
68 1
    public function inverse()
69
    {
70 1
        return $this->addCssClass(FA::$cssPrefix . '-inverse');
71
    }
72
73
    /**
74
     * @return self
75
     */
76 3
    public function spin()
77
    {
78 3
        return $this->addCssClass(FA::$cssPrefix . '-spin');
79
    }
80
    
81
    /**
82
     * @return self
83
     */
84
    public function pulse()
85
    {
86
        return $this->addCssClass(FA::$cssPrefix . '-pulse');
87
    }
88
89
    /**
90
     * @return self
91
     */
92 1
    public function fixedWidth()
93
    {
94 1
        return $this->addCssClass(FA::$cssPrefix . '-fw');
95
    }
96
97
    /**
98
     * @return self
99
     */
100 3
    public function li()
101
    {
102 3
        return $this->addCssClass(FA::$cssPrefix . '-li');
103
    }
104
105
    /**
106
     * @return self
107
     */
108 1
    public function border()
109
    {
110 1
        return $this->addCssClass(FA::$cssPrefix . '-border');
111
    }
112
113
    /**
114
     * @return self
115
     */
116 1
    public function pullLeft()
117
    {
118 1
        return $this->addCssClass(FA::$cssPrefix . '-pull-left');
119
    }
120
121
    /**
122
     * @return self
123
     */
124 1
    public function pullRight()
125
    {
126 1
        return $this->addCssClass(FA::$cssPrefix . '-pull-right');
127
    }
128
129
    /**
130
     * @param string $value
131
     * @return self
132
     * @throws \yii\base\InvalidConfigException
133
     */
134 4
    public function size($value)
135
    {
136 4
        return $this->addCssClass(
137 4
            FA::$cssPrefix . '-' . $value,
138 4
            in_array((string)$value, [FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X], true),
139 4
            sprintf(
140 4
                '%s - invalid value. Use one of the constants: %s.',
141 4
                'FA::size()',
142
                'FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X'
143 4
            )
144 4
        );
145
    }
146
147
    /**
148
     * @param string $value
149
     * @return self
150
     * @throws \yii\base\InvalidConfigException
151
     */
152 2 View Code Duplication
    public function rotate($value)
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...
153
    {
154 2
        return $this->addCssClass(
155 2
            FA::$cssPrefix . '-rotate-' . $value,
156 2
            in_array((string)$value, [FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270], true),
157 2
            sprintf(
158 2
                '%s - invalid value. Use one of the constants: %s.',
159 2
                'FA::rotate()',
160
                'FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270'
161 2
            )
162 2
        );
163
    }
164
165
    /**
166
     * @param string $value
167
     * @return self
168
     * @throws \yii\base\InvalidConfigException
169
     */
170 2 View Code Duplication
    public function flip($value)
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...
171
    {
172 2
        return $this->addCssClass(
173 2
            FA::$cssPrefix . '-flip-' . $value,
174 2
            in_array((string)$value, [FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL], true),
175 2
            sprintf(
176 2
                '%s - invalid value. Use one of the constants: %s.',
177 2
                'FA::flip()',
178
                'FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL'
179 2
            )
180 2
        );
181
    }
182
183
    /**
184
     * @deprecated
185
     * Change html tag.
186
     * @param string $tag
187
     * @return static
188
     * @throws \yii\base\InvalidParamException
189
     */
190 2
    public function tag($tag)
191
    {
192 2
        $this->tag = $tag;
0 ignored issues
show
Deprecated Code introduced by
The property rmrevin\yii\fontawesome\component\Icon::$tag has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
193
194 2
        $this->options['tag'] = $tag;
195
196 2
        return $this;
197
    }
198
199
    /**
200
     * @param string $class
201
     * @param bool $condition
202
     * @param string|bool $throw
203
     * @return \rmrevin\yii\fontawesome\component\Icon
204
     * @throws \yii\base\InvalidConfigException
205
     * @codeCoverageIgnore
206
     */
207
    public function addCssClass($class, $condition = true, $throw = false)
208
    {
209
        if ($condition === false) {
210
            if (!empty($throw)) {
211
                $message = !is_string($throw)
212
                    ? 'Condition is false'
213
                    : $throw;
214
215
                throw new \yii\base\InvalidConfigException($message);
216
            }
217
        } else {
218
            Html::addCssClass($this->options, $class);
219
        }
220
221
        return $this;
222
    }
223
224
    /**
225
     * @deprecated
226
     * @param string|null $tag
227
     * @param string|null $content
228
     * @param array $options
229
     * @return string
230
     */
231 View Code Duplication
    public function render($tag = null, $content = null, $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...
232
    {
233
        $tag = empty($tag)
234
            ? (empty($this->tag) ? static::$defaultTag : $this->tag)
0 ignored issues
show
Deprecated Code introduced by
The property rmrevin\yii\fontawesome\component\Icon::$tag has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The property rmrevin\yii\fontawesome\...onent\Icon::$defaultTag has been deprecated.

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
235
            : $tag;
236
237
        $options = array_merge($this->options, $options);
238
239
        return Html::tag($tag, $content, $options);
240
    }
241
}
242