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 (#58)
by Lukas
02:22
created

OneSignalMessage::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

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