CardAttribute   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 148
Duplicated Lines 10.81 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 16
loc 148
ccs 35
cts 35
cp 1
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 6 1
A label() 0 6 1
A url() 0 6 1
A style() 0 6 1
A icon() 10 10 2
A __construct() 0 5 1
A create() 0 4 1
A toArray() 6 23 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
namespace NotificationChannels\HipChat;
4
5
class CardAttribute
6
{
7
    /**
8
     * @var string
9
     */
10
    public $value;
11
12
    /**
13
     * @var string
14
     */
15
    public $label;
16
17
    /**
18
     * @var string
19
     */
20
    public $url;
21
22
    /**
23
     * @var string
24
     */
25
    public $style;
26
27
    /**
28
     * @var string
29
     */
30
    public $icon;
31
32
    /**
33
     * @var string
34
     */
35
    public $icon2;
36
37
    /**
38
     * Sets the textual value of the attribute.
39
     *
40
     * @param string $value
41
     * @return $this
42
     */
43 9
    public function value($value)
44
    {
45 9
        $this->value = trim($value);
46
47 9
        return $this;
48
    }
49
50
    /**
51
     * Sets the label of the attribute.
52
     *
53
     * @param string $label
54
     * @return $this
55
     */
56 9
    public function label($label)
57
    {
58 9
        $this->label = trim($label);
59
60 9
        return $this;
61
    }
62
63
    /**
64
     * @param string $url
65
     * @return $this
66
     */
67 2
    public function url($url)
68
    {
69 2
        $this->url = trim($url);
70
71 2
        return $this;
72
    }
73
74
    /**
75
     * Sets the style for the attribute.
76
     *
77
     * @param string $style
78
     * @return $this
79
     */
80 2
    public function style($style)
81
    {
82 2
        $this->style = trim($style);
83
84 2
        return $this;
85
    }
86
87
    /**
88
     * Sets the icon for the attribute.
89
     *
90
     * @param string $icon
91
     * @param string|null $icon2
92
     * @return $this
93
     */
94 3 View Code Duplication
    public function icon($icon, $icon2 = null)
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...
95
    {
96 3
        $this->icon = trim($icon);
97
98 3
        if (! str_empty($icon2)) {
99 2
            $this->icon2 = trim($icon2);
100
        }
101
102 3
        return $this;
103
    }
104
105
    /**
106
     * Create a new instance of the attribute.
107
     *
108
     * @param string $label
109
     * @param string $value
110
     */
111 9
    public function __construct($value = null, $label = null)
112
    {
113 9
        $this->value($value);
114 9
        $this->label($label);
115 9
    }
116
117
    /**
118
     * Create a new instance of the attribute.
119
     *
120
     * @param string $value
121
     * @param string $label
122
     * @return static
123
     */
124 7
    public static function create($value = null, $label = null)
125
    {
126 7
        return new static($value, $label);
127
    }
128
129 5
    public function toArray()
130
    {
131
        $attribute = [
132 5
            'value' => str_array_filter([
133 5
                'label' => $this->value,
134 5
                'url' => $this->url,
135 5
                'style' => $this->style,
136
            ]),
137
        ];
138
139 5 View Code Duplication
        if (! str_empty($this->icon)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
140 3
            $attribute['value']['icon'] = str_array_filter([
141 3
                'url' => $this->icon,
142 3
                'url@2x' => $this->icon2,
143
            ]);
144
        }
145
146 5
        if (! str_empty($this->label)) {
147 4
            $attribute['label'] = $this->label;
148
        }
149
150 5
        return $attribute;
151
    }
152
}
153