Completed
Push — master ( 3f8806...162df9 )
by Peter
02:17
created

CardAttribute::style()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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
    public function value($value)
44
    {
45
        $this->value = trim($value);
46
47
        return $this;
48
    }
49
50
    /**
51
     * Sets the label of the attribute.
52
     *
53
     * @param string $label
54
     * @return $this
55
     */
56
    public function label($label)
57
    {
58
        $this->label = trim($label);
59
60
        return $this;
61
    }
62
63
    /**
64
     * @param string $url
65
     * @return $this
66
     */
67
    public function url($url)
68
    {
69
        $this->url = trim($url);
70
71
        return $this;
72
    }
73
74
    /**
75
     * Sets the style for the attribute.
76
     *
77
     * @param string $style
78
     * @return $this
79
     */
80
    public function style($style)
81
    {
82
        $this->style = trim($style);
83
84
        return $this;
85
    }
86
87
    /**
88
     * Sets the icon for the atttribute.
89
     *
90
     * @param string $icon
91
     * @param string|null $icon2
92
     * @return $this
93
     */
94 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
        $this->icon = trim($icon);
97
98
        if (! empty($icon2)) {
99
            $this->icon2 = trim($icon2);
100
        }
101
102
        return $this;
103
    }
104
105
    /**
106
     * Create a new instance of the attribute.
107
     *
108
     * @param string $label
109
     * @param string $value
110
     */
111
    public function __construct($value = null, $label = null)
112
    {
113
        if (! empty($value)) {
114
            $this->value($value);
115
        }
116
117
        if (! empty($label)) {
118
            $this->label($label);
119
        }
120
    }
121
122
    /**
123
     * Create a new instance of the attribute.
124
     *
125
     * @param string $value
126
     * @param string $label
127
     * @return static
128
     */
129
    public static function create($value = null, $label = null)
130
    {
131
        return new static($value, $label);
132
    }
133
134
    public function toArray()
135
    {
136
        $attribute = [
137
            'value' => array_filter([
138
                'label' => $this->value,
139
                'url' => $this->url,
140
                'style' => $this->style,
141
            ]),
142
        ];
143
144
        if (! empty($this->icon)) {
145
            $attribute['value']['icon'] = array_filter([
146
                'url' => $this->icon,
147
                'url@2x' => $this->icon2,
148
            ]);
149
        }
150
151
        if (! empty($this->label)) {
152
            $attribute['label'] = $this->label;
153
        }
154
155
        return $attribute;
156
    }
157
}
158