Completed
Push — master ( 665c45...e77f4f )
by Peter
02:48
created

src/CardAttribute.php (1 issue)

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
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 4
    public function value($value)
44
    {
45 4
        $this->value = trim($value);
46
47 4
        return $this;
48
    }
49
50
    /**
51
     * Sets the label of the attribute.
52
     *
53
     * @param string $label
54
     * @return $this
55
     */
56 3
    public function label($label)
57
    {
58 3
        $this->label = trim($label);
59
60 3
        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 atttribute.
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
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 (! 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 7
    public function __construct($value = null, $label = null)
112
    {
113 7
        if (! empty($value)) {
114
            $this->value($value);
115
        }
116
117 7
        if (! empty($label)) {
118
            $this->label($label);
119
        }
120 7
    }
121
122
    /**
123
     * Create a new instance of the attribute.
124
     *
125
     * @param string $value
126
     * @param string $label
127
     * @return static
128
     */
129 5
    public static function create($value = null, $label = null)
130
    {
131 5
        return new static($value, $label);
132
    }
133
134 3
    public function toArray()
135
    {
136
        $attribute = [
137 3
            'value' => array_filter([
138 3
                'label' => $this->value,
139 3
                'url' => $this->url,
140 3
                'style' => $this->style,
141
            ]),
142
        ];
143
144 3
        if (! empty($this->icon)) {
145 3
            $attribute['value']['icon'] = array_filter([
146 3
                'url' => $this->icon,
147 3
                'url@2x' => $this->icon2,
148
            ]);
149
        }
150
151 3
        if (! empty($this->label)) {
152 2
            $attribute['label'] = $this->label;
153
        }
154
155 3
        return $attribute;
156
    }
157
}
158