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

component/UnorderedList.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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