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

UnorderedList   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 92
Duplicated Lines 13.04 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 3
dl 12
loc 92
ccs 23
cts 23
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __toString() 0 4 1
A item() 0 12 2
A tag() 0 6 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\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 Revin Roman
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