GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#18)
by
unknown
08:03
created

OneSignalMessage::setData()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 10
ccs 4
cts 6
cp 0.6667
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 6
nc 2
nop 2
crap 2.1481
1
<?php
2
3
namespace NotificationChannels\OneSignal;
4
5
use Illuminate\Support\Arr;
6
7
class OneSignalMessage
8
{
9
    /** @var string */
10
    protected $body;
11
12
    /** @var string */
13
    protected $subject;
14
15
    /** @var string */
16
    protected $url;
17
18
    /** @var string */
19
    protected $sound;
20
21
    /** @var string */
22
    protected $icon;
23
24
    /** @var array */
25
    protected $data = [];
26
27
    /** @var array */
28
    protected $buttons = [];
29
30
    /** @var array */
31
    protected $webButtons = [];
32
33
    /**
34
     * @param string $body
35
     *
36
     * @return static
37
     */
38 1
    public static function create($body = '')
39
    {
40 1
        return new static($body);
41
    }
42
43
    /**
44
     * @param string $body
45
     */
46 11
    public function __construct($body = '')
47
    {
48 11
        $this->body = $body;
49 11
    }
50
51
    /**
52
     * Set the message body.
53
     *
54
     * @param string $value
55
     *
56
     * @return $this
57
     */
58 1
    public function body($value)
59
    {
60 1
        $this->body = $value;
61
62 1
        return $this;
63
    }
64
65
    /**
66
     * Set the message icon.
67
     *
68
     * @param string $value
69
     *
70
     * @return $this
71
     */
72 3
    public function icon($value)
73
    {
74 3
        $this->icon = $value;
75
76 3
        return $this;
77
    }
78
79
    /**
80
     * Set the message sound.
81
     *
82
     * @param string $value
83
     *
84
     * @return $this
85
     */
86
    public function sound($value)
87
    {
88
        $this->sound = $value;
89
90
        return $this;
91
    }
92
93
    /**
94
     * Set the message subject.
95
     *
96
     * @param string $value
97
     *
98
     * @return $this
99
     */
100 3
    public function subject($value)
101
    {
102 3
        $this->subject = $value;
103
104 3
        return $this;
105
    }
106
107
    /**
108
     * Set the message url.
109
     *
110
     * @param string $value
111
     *
112
     * @return $this
113
     */
114 3
    public function url($value)
115
    {
116 3
        $this->url = $value;
117
118 3
        return $this;
119
    }
120
121
    /**
122
     * Set additional data.
123
     *
124
     * @param mixed $key
125
     * @param string $value
126
     *
127
     * @return $this
128
     */
129 1
    public function setData($key, $value = null)
130
    {
131 1
        if (is_array($key)) {
132
            array_merge($this->data, $key);
133
        } else {
134 1
            $this->data[$key] = $value;
135
        }
136
137 1
        return $this;
138
    }
139
140
    /**
141
     * Add a web button to the message.
142
     *
143
     * @param OneSignalWebButton $button
144
     *
145
     * @return $this
146
     */
147 1
    public function webButton(OneSignalWebButton $button)
148
    {
149 1
        $this->webButtons[] = $button->toArray();
150
151 1
        return $this;
152
    }
153
154
    /**
155
     * Add a native button to the message.
156
     *
157
     * @param OneSignalButton $button
158
     *
159
     * @return $this
160
     */
161 1
    public function button(OneSignalButton $button)
162
    {
163 1
        $this->buttons[] = $button->toArray();
164
165 1
        return $this;
166
    }
167
168
    /**
169
     * @return array
170
     */
171 11
    public function toArray()
172
    {
173
        $message = [
174 11
            'contents' => ['en' => $this->body],
175 11
            'headings' => ['en' => $this->subject],
176 11
            'url' => $this->url,
177 11
            'buttons' => $this->buttons,
178 11
            'web_buttons' => $this->webButtons,
179 11
            'chrome_web_icon' => $this->icon,
180 11
            'chrome_icon' => $this->icon,
181 11
            'adm_small_icon' => $this->icon,
182 11
            'small_icon' => $this->icon,
183 11
            'ios_sound' => $this->sound,
184 11
            'android_sound' => $this->sound,
185 11
            'adm_sound' => $this->sound,
186 11
            'wp_sound' => $this->sound
187 11
        ];
188
189 11
        foreach ($this->data as $data => $value) {
190 1
            Arr::set($message, 'data.'.$data, $value);
191 11
        }
192
193 11
        return $message;
194
    }
195
}
196