Completed
Push — master ( 759093...8330b4 )
by Revin
01:29
created

UnorderedList   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 4
dl 0
loc 62
ccs 0
cts 24
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 1
A __toString() 0 4 1
A item() 0 17 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\FontAwesome;
11
use yii\helpers\ArrayHelper;
12
use yii\helpers\Html;
13
14
/**
15
 * Class UnorderedList
16
 * @package rmrevin\yii\fontawesome\component
17
 */
18
class UnorderedList
19
{
20
    protected $iconCssPrefix;
21
22
    /**
23
     * @var array
24
     */
25
    protected $options = [];
26
27
    /**
28
     * @var array
29
     */
30
    protected $items = [];
31
32
    /**
33
     * @param string $iconCssPrefix
34
     * @param array $options
35
     */
36
    public function __construct($iconCssPrefix, $options = [])
37
    {
38
        $this->iconCssPrefix = $iconCssPrefix;
39
40
        Html::addCssClass($options, FontAwesome::$basePrefix . '-ul');
41
42
        $options['item'] = function ($item, $index) {
43
            return call_user_func($item, $index);
44
        };
45
46
        $this->options = $options;
47
    }
48
49
    /**
50
     * @return string
51
     */
52
    public function __toString()
53
    {
54
        return Html::ul($this->items, $this->options);
55
    }
56
57
    /**
58
     * @param string $label
59
     * @param array $options
60
     * @return \rmrevin\yii\fontawesome\component\UnorderedList
61
     */
62
    public function item($label, $options = [])
63
    {
64
        $this->items[] = function ($index) use ($label, $options) {
0 ignored issues
show
Unused Code introduced by
The parameter $index is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
65
            $tag = ArrayHelper::remove($options, 'tag', 'li');
66
67
            $icon = ArrayHelper::remove($options, 'icon');
68
            $icon = empty($icon)
69
                ? null
70
                : (is_string($icon) ? (string)(new Icon($this->iconCssPrefix, $icon))->li() : $icon);
71
72
            $content = trim($icon . $label);
73
74
            return Html::tag($tag, $content, $options);
75
        };
76
77
        return $this;
78
    }
79
}
80