Completed
Push — master ( 470202...7f8aea )
by Revin
02:39
created

UnorderedList   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 106
Duplicated Lines 11.32 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 74.07%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 4
dl 12
loc 106
rs 10
ccs 20
cts 27
cp 0.7407

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __toString() 0 4 1
A item() 0 17 3
A tag() 0 8 1
A render() 12 12 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\ArrayHelper;
12
use yii\helpers\Html;
13
14
/**
15
 * Class UnorderedList
16
 * @package rmrevin\yii\fontawesome\component
17
 */
18
class UnorderedList
19
{
20
21
    /**
22
     * @deprecated
23
     * @var string
24
     */
25
    public static $defaultTag = 'ul';
26
27
    /**
28
     * @deprecated
29
     * @var string
30
     */
31
    private $tag;
32
33
    /**
34
     * @var array
35
     */
36
    protected $options = [];
37
38
    /**
39
     * @var array
40
     */
41
    protected $items = [];
42
43
    /**
44
     * @param array $options
45
     */
46 2
    public function __construct($options = [])
47
    {
48 2
        Html::addCssClass($options, FA::$cssPrefix . '-ul');
49
50
        $options['item'] = function ($item, $index) {
51 2
            return call_user_func($item, $index);
52
        };
53
54 2
        $this->options = $options;
55 2
    }
56
57
    /**
58
     * @return string
59
     */
60 2
    public function __toString()
61
    {
62 2
        return Html::ul($this->items, $this->options);
63
    }
64
65
    /**
66
     * @param string $label
67
     * @param array $options
68
     * @return static
69
     */
70
    public function item($label, $options = [])
71
    {
72 2
        $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...
73 2
            $tag = ArrayHelper::remove($options, 'tag', 'li');
74
75 2
            $icon = ArrayHelper::remove($options, 'icon');
76 2
            $icon = empty($icon)
77 2
                ? null
78 2
                : (is_string($icon) ? (string)(new Icon($icon))->li() : $icon);
79
80 2
            $content = trim($icon . $label);
81
82 2
            return Html::tag($tag, $content, $options);
83
        };
84
85 2
        return $this;
86
    }
87
88
    /**
89
     * @deprecated
90
     * Change html tag.
91
     * @param string $tag
92
     * @return static
93
     * @throws \yii\base\InvalidParamException
94
     */
95 1
    public function tag($tag)
96
    {
97 1
        $this->tag = $tag;
0 ignored issues
show
Deprecated Code introduced by
The property rmrevin\yii\fontawesome\...ent\UnorderedList::$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...
98
99 1
        $this->options['tag'] = $tag;
100
101 1
        return $this;
102
    }
103
104
    /**
105
     * @deprecated
106
     * @param string|null $tag
107
     * @param array $options
108
     * @return string
109
     * @throws \yii\base\InvalidConfigException
110
     */
111 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...
112
    {
113
        $tag = empty($tag)
114
            ? (empty($this->tag) ? static::$defaultTag : $this->tag)
0 ignored issues
show
Deprecated Code introduced by
The property rmrevin\yii\fontawesome\...ent\UnorderedList::$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\...rderedList::$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...
115
            : $tag;
116
117
        $options = array_merge($this->options, $options);
118
119
        $items = $this->items;
120
121
        return Html::tag($tag, implode($items), $options);
122
    }
123
}
124