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.

OneSignalMessage::setData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace NotificationChannels\OneSignal;
4
5
use Illuminate\Support\Arr;
6
use NotificationChannels\OneSignal\Traits\Categories\AppearanceHelpers;
7
use NotificationChannels\OneSignal\Traits\Categories\AttachmentHelpers;
8
use NotificationChannels\OneSignal\Traits\Categories\ButtonHelpers;
9
use NotificationChannels\OneSignal\Traits\Categories\DeliveryHelpers;
10
use NotificationChannels\OneSignal\Traits\Categories\GroupingHelpers;
11
use NotificationChannels\OneSignal\Traits\Categories\SilentHelpers;
12
use NotificationChannels\OneSignal\Traits\Deprecated;
13
14
class OneSignalMessage
15
{
16
    use AppearanceHelpers, AttachmentHelpers, ButtonHelpers, DeliveryHelpers, GroupingHelpers, SilentHelpers, Deprecated;
17
18
    /** @var array */
19
    protected $payload = [];
20
21
    /**
22
     * @param string $body
23
     *
24
     * @return static
25
     */
26 1
    public static function create($body = '')
27
    {
28 1
        return new static($body);
29
    }
30
31
    /**
32
     * @param string $body
33
     */
34 25
    public function __construct($body = '')
35
    {
36 25
        $this->setBody($body);
37 25
    }
38
39
    /**
40
     * Set the message body.
41
     *
42
     * @param mixed $value
43
     *
44
     * @return $this
45
     */
46 25
    public function setBody($value)
47
    {
48 25
        return $this->setParameter('contents', $this->parseValueToArray($value));
49
    }
50
51
    /**
52
     * Set the message subject.
53
     *
54
     * @param mixed $value
55
     *
56
     * @return $this
57
     */
58 1
    public function setSubject($value)
59
    {
60 1
        return $this->setParameter('headings', $this->parseValueToArray($value));
61
    }
62
63
    /**
64
     * Set the message template_id.
65
     *
66
     * @param string $value
67
     *
68
     * @return $this
69
     */
70
    public function setTemplate($value)
71
    {
72
        Arr::forget($this->payload, 'contents');
73
74
        return $this->setParameter('template_id', $value);
75
    }
76
77
    /**
78
     * @param mixed $value
79
     *
80
     * @return array
81
     */
82 25
    protected function parseValueToArray($value)
83
    {
84 25
        return (is_array($value)) ? $value : ['en' => $value];
85
    }
86
87
    /**
88
     * Set additional data.
89
     *
90
     * @param string $key
91
     * @param mixed  $value
92
     *
93
     * @return $this
94
     */
95 1
    public function setData(string $key, $value)
96
    {
97 1
        return $this->setParameter("data.{$key}", $value);
98
    }
99
100
    /**
101
     * Set parameters.
102
     *
103
     * @param string $key
104
     * @param mixed  $value
105
     *
106
     * @return $this
107
     */
108 25
    public function setParameter(string $key, $value)
109
    {
110 25
        Arr::set($this->payload, $key, $value);
111
112 25
        return $this;
113
    }
114
115
    /**
116
     * Get parameters.
117
     *
118
     * @param string $key
119
     * @param mixed  $default
120
     *
121
     * @return mixed
122
     */
123 3
    public function getParameter(string $key, $default = null)
124
    {
125 3
        return Arr::get($this->payload, $key, $default);
126
    }
127
128
    /**
129
     * @return array
130
     */
131 25
    public function toArray()
132
    {
133 25
        return $this->payload;
134
    }
135
}
136