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
Push — master ( 06f31e...5d2f0f )
by Lukas
01:57
created

OneSignalMessage::subjectToArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
crap 2
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 $icon;
20
21
    /** @var array */
22
    protected $data = [];
23
24
    /** @var array */
25
    protected $buttons = [];
26
27
    /** @var array */
28
    protected $webButtons = [];
29
30
    /** @var array */
31
    protected $extraParameters = [];
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 17
    public function __construct($body = '')
47
    {
48 17
        $this->body = $body;
49 17
    }
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 6
    public function icon($value)
73
    {
74 6
        $this->icon = $value;
75
76 6
        return $this;
77
    }
78
79
    /**
80
     * Set the message subject.
81
     *
82
     * @param string $value
83
     *
84
     * @return $this
85
     */
86 6
    public function subject($value)
87
    {
88 6
        $this->subject = $value;
89
90 6
        return $this;
91
    }
92
93
    /**
94
     * Set the message url.
95
     *
96
     * @param string $value
97
     *
98
     * @return $this
99
     */
100 6
    public function url($value)
101
    {
102 6
        $this->url = $value;
103
104 6
        return $this;
105
    }
106
107
    /**
108
     * Set additional data.
109
     *
110
     * @param string $key
111
     * @param string $value
112
     *
113
     * @return $this
114
     */
115 1
    public function setData($key, $value)
116
    {
117 1
        $this->data[$key] = $value;
118
119 1
        return $this;
120
    }
121
122
    /**
123
     * Set additional parameters.
124
     *
125
     * @param string $key
126
     * @param string $value
127
     *
128
     * @return $this
129
     */
130 1
    public function setParameter($key, $value)
131
    {
132 1
        $this->extraParameters[$key] = $value;
133
134 1
        return $this;
135
    }
136
137
    /**
138
     * Add a web button to the message.
139
     *
140
     * @param OneSignalWebButton $button
141
     *
142
     * @return $this
143
     */
144 1
    public function webButton(OneSignalWebButton $button)
145
    {
146 1
        $this->webButtons[] = $button->toArray();
147
148 1
        return $this;
149
    }
150
151
    /**
152
     * Add a native button to the message.
153
     *
154
     * @param OneSignalButton $button
155
     *
156
     * @return $this
157
     */
158 1
    public function button(OneSignalButton $button)
159
    {
160 1
        $this->buttons[] = $button->toArray();
161
162 1
        return $this;
163
    }
164
165
    /**
166
     * Set an image to all possible attachment variables.
167
     * @param string $imageUrl
168
     *
169
     * @return $this
170
     */
171 1
    public function setImageAttachments($imageUrl)
172
    {
173 1
        $this->extraParameters['ios_attachments']['id1'] = $imageUrl;
174 1
        $this->extraParameters['big_picture'] = $imageUrl;
175 1
        $this->extraParameters['adm_big_picture'] = $imageUrl;
176 1
        $this->extraParameters['chrome_big_picture'] = $imageUrl;
177
178 1
        return $this;
179
    }
180
181
    /**
182
     * @return array
183
     */
184 17
    public function toArray()
185
    {
186
        $message = [
187 17
            'contents' => ['en' => $this->body],
188 17
            'headings' => $this->subjectToArray(),
189 17
            'url' => $this->url,
190 17
            'buttons' => $this->buttons,
191 17
            'web_buttons' => $this->webButtons,
192 17
            'chrome_web_icon' => $this->icon,
193 17
            'chrome_icon' => $this->icon,
194 17
            'adm_small_icon' => $this->icon,
195 17
            'small_icon' => $this->icon,
196
        ];
197
198 17
        foreach ($this->extraParameters as $key => $value) {
199 2
            Arr::set($message, $key, $value);
200
        }
201
202 17
        foreach ($this->data as $data => $value) {
203 1
            Arr::set($message, 'data.'.$data, $value);
204
        }
205
206 17
        return $message;
207
    }
208
209 17
    protected function subjectToArray()
210
    {
211 17
        if ($this->subject === null) {
212 11
            return [];
213
        }
214
215 6
        return ['en' => $this->subject];
216
    }
217
}
218