Completed
Push — master ( 7e2aaa...d03d67 )
by Revin
02:22
created

Icon::pullRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
ccs 2
cts 2
cp 1
cc 1
eloc 2
nc 1
nop 0
crap 1
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\Html;
12
13
/**
14
 * Class Icon
15
 * @package rmrevin\yii\fontawesome\component
16
 */
17
class Icon
18
{
19
20
    /** @var string */
21
    public static $defaultTag = 'i';
22
23
    /** @var string */
24
    private $tag;
25
26
    /** @var array */
27
    private $options = [];
28
29
    /**
30
     * @param string $name
31
     * @param array $options
32
     */
33 9
    public function __construct($name, $options = [])
34
    {
35 9
        Html::addCssClass($options, FA::$cssPrefix);
36 9
        if (!empty($name)) {
37 9
            Html::addCssClass($options, FA::$cssPrefix . '-' . $name);
38 9
        }
39
40 9
        $this->options = $options;
41 9
    }
42
43
    /**
44
     * @return string
45
     */
46 5
    public function __toString()
47
    {
48 5
        return $this->render();
49
    }
50
51
    /**
52
     * @return self
53
     */
54 1
    public function inverse()
55
    {
56 1
        return $this->addCssClass(FA::$cssPrefix . '-inverse');
57
    }
58
59
    /**
60
     * @return self
61
     */
62 2
    public function spin()
63
    {
64 2
        return $this->addCssClass(FA::$cssPrefix . '-spin');
65
    }
66
67
    /**
68
     * @deprecated
69
     * @return self
70
     */
71 1
    public function fixed_width()
72
    {
73 1
        \Yii::warning(sprintf('You are using an deprecated method `%s`.', 'fixed_width'), __METHOD__);
74
75 1
        return $this->fixedWidth();
76
    }
77
78
    /**
79
     * @return self
80
     */
81 1
    public function fixedWidth()
82
    {
83 1
        return $this->addCssClass(FA::$cssPrefix . '-fw');
84
    }
85
86
    /**
87
     * @return self
88
     */
89 1
    public function ul()
90
    {
91 1
        return $this->addCssClass(FA::$cssPrefix . '-ul');
92
    }
93
94
    /**
95
     * @return self
96
     */
97 1
    public function li()
98
    {
99 1
        return $this->addCssClass(FA::$cssPrefix . '-li');
100
    }
101
102
    /**
103
     * @return self
104
     */
105 1
    public function border()
106
    {
107 1
        return $this->addCssClass(FA::$cssPrefix . '-border');
108
    }
109
110
    /**
111
     * @deprecated
112
     * @return self
113
     */
114 1
    public function pull_left()
115
    {
116 1
        \Yii::warning(sprintf('You are using an deprecated method `%s`.', 'pull_left'), __METHOD__);
117
118 1
        return $this->pullLeft();
119
    }
120
121
    /**
122
     * @return self
123
     */
124 1
    public function pullLeft()
125
    {
126 1
        return $this->addCssClass('pull-left');
127
    }
128
129
    /**
130
     * @deprecated
131
     * @return self
132
     */
133 1
    public function pull_right()
134
    {
135 1
        \Yii::warning(sprintf('You are using an deprecated method `%s`.', 'pull_right'), __METHOD__);
136
137 1
        return $this->pullRight();
138
    }
139
140
    /**
141
     * @return self
142
     */
143 1
    public function pullRight()
144
    {
145 1
        return $this->addCssClass('pull-right');
146
    }
147
148
    /**
149
     * @param string $value
150
     * @return self
151
     * @throws \yii\base\InvalidConfigException
152
     */
153 3
    public function size($value)
154
    {
155 3
        return $this->addCssClass(
156 3
            FA::$cssPrefix . '-' . $value,
157 3
            in_array((string)$value, [FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X], true),
158 3
            sprintf(
159 3
                '%s - invalid value. Use one of the constants: %s.',
160 3
                'FA::size()',
161
                'FA::SIZE_LARGE, FA::SIZE_2X, FA::SIZE_3X, FA::SIZE_4X, FA::SIZE_5X'
162 3
            )
163 3
        );
164
    }
165
166
    /**
167
     * @param string $value
168
     * @return self
169
     * @throws \yii\base\InvalidConfigException
170
     */
171 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...
172
    {
173 2
        return $this->addCssClass(
174 2
            FA::$cssPrefix . '-rotate-' . $value,
175 2
            in_array((string)$value, [FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270], true),
176 2
            sprintf(
177 2
                '%s - invalid value. Use one of the constants: %s.',
178 2
                'FA::rotate()',
179
                'FA::ROTATE_90, FA::ROTATE_180, FA::ROTATE_270'
180 2
            )
181 2
        );
182
    }
183
184
    /**
185
     * @param string $value
186
     * @return self
187
     * @throws \yii\base\InvalidConfigException
188
     */
189 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...
190
    {
191 2
        return $this->addCssClass(
192 2
            FA::$cssPrefix . '-flip-' . $value,
193 2
            in_array((string)$value, [FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL], true),
194 2
            sprintf(
195 2
                '%s - invalid value. Use one of the constants: %s.',
196 2
                'FA::flip()',
197
                'FA::FLIP_HORIZONTAL, FA::FLIP_VERTICAL'
198 2
            )
199 2
        );
200
    }
201
202
    /**
203
     * Change html tag.
204
     * @param string $tag
205
     * @return static
206
     * @throws \yii\base\InvalidParamException
207
     */
208 2
    public function tag($tag)
209
    {
210 2
        $this->tag = $tag;
211
212 2
        return $this;
213
    }
214
215
    /**
216
     * @param string $class
217
     * @param bool $condition
218
     * @param string|bool $throw
219
     * @return \rmrevin\yii\fontawesome\component\Icon
220
     * @throws \yii\base\InvalidConfigException
221
     * @codeCoverageIgnore
222
     */
223
    public function addCssClass($class, $condition = true, $throw = false)
224
    {
225
        if ($condition === false) {
226
            if (!empty($throw)) {
227
                $message = !is_string($throw)
228
                    ? 'Condition is false'
229
                    : $throw;
230
231
                throw new \yii\base\InvalidConfigException($message);
232
            }
233
        } else {
234
            Html::addCssClass($this->options, $class);
235
        }
236
237
        return $this;
238
    }
239
240
    /**
241
     * @param string|null $tag
242
     * @param string|null $content
243
     * @param array $options
244
     * @return string
245
     */
246 5
    public function render($tag = null, $content = null, $options = [])
247
    {
248 5
        $tag = empty($tag)
249 5
            ? (empty($this->tag) ? static::$defaultTag : $this->tag)
250 5
            : $tag;
251
252 5
        $options = array_merge($this->options, $options);
253
254 5
        return Html::tag($tag, $content, $options);
255
    }
256
}