Completed
Push — master ( 23e282...478907 )
by Revin
02:44
created

UnorderedList::render()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 12
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 12
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
cc 3
eloc 7
nc 4
nop 2
crap 3
1
<?php
2
/**
3
 * UnorderedList.php
4
 * @author Revin Roman
5
 * @link https://rmrevin.com
6
 */
7
8
namespace rmrevin\yii\fontawesome\component;
9
10
use rmrevin\yii\fontawesome\FA;
11
use yii\helpers\Html;
12
13
/**
14
 * Class UnorderedList
15
 * @package rmrevin\yii\fontawesome\component
16
 */
17
class UnorderedList
18
{
19
20
    /**
21
     * @var string
22
     */
23
    public static $defaultTag = 'ul';
24
25
    /**
26
     * @var string
27
     */
28
    private $tag;
29
30
    /**
31
     * @var array
32
     */
33
    private $options = [];
34
35
    /**
36
     * @var array
37
     */
38
    private $items = [];
39
40
    /**
41
     * @param array $options
42
     */
43 2
    public function __construct($options = [])
44
    {
45 2
        Html::addCssClass($options, FA::$cssPrefix . '-ul');
46
47 2
        $this->options = $options;
48 2
    }
49
50
    /**
51
     * @return string
52
     */
53 2
    public function __toString()
54
    {
55 2
        return $this->render();
56
    }
57
58
    /**
59
     * @param string|Icon $icon
60
     * @param string|null $label
61
     * @param array $options
62
     * @return static
63
     */
64 2
    public function item($icon, $label = null, $options = [])
65
    {
66 2
        if (is_string($icon)) {
67 2
            $icon = new Icon($icon, $options);
68 2
        }
69
70 2
        $content = trim((string)$icon->li() . $label);
71
72 2
        $this->items[] = Html::tag('li', $content);
73
74 2
        return $this;
75
    }
76
77
    /**
78
     * Change html tag.
79
     * @param string $tag
80
     * @return static
81
     * @throws \yii\base\InvalidParamException
82
     */
83 1
    public function tag($tag)
84
    {
85 1
        $this->tag = $tag;
86
87 1
        return $this;
88
    }
89
90
    /**
91
     * @param string|null $tag
92
     * @param array $options
93
     * @return string
94
     * @throws \yii\base\InvalidConfigException
95
     */
96 2 View Code Duplication
    public function render($tag = 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...
97
    {
98 2
        $tag = empty($tag)
99 2
            ? (empty($this->tag) ? static::$defaultTag : $this->tag)
100 2
            : $tag;
101
102 2
        $options = array_merge($this->options, $options);
103
104 2
        $items = $this->items;
105
106 2
        return Html::tag($tag, implode($items), $options);
107
    }
108
}
109