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
07:53 queued 14s
created

OneSignalMessage::setSubject()   A

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 1
crap 1
1
<?php
2
3
namespace NotificationChannels\OneSignal;
4
5
use Illuminate\Support\Arr;
6
use NotificationChannels\OneSignal\Traits\Deprecated;
7
use NotificationChannels\OneSignal\Traits\Categories\ButtonHelpers;
8
use NotificationChannels\OneSignal\Traits\Categories\SilentHelpers;
9
use NotificationChannels\OneSignal\Traits\Categories\DeliveryHelpers;
10
use NotificationChannels\OneSignal\Traits\Categories\GroupingHelpers;
11
use NotificationChannels\OneSignal\Traits\Categories\AppearanceHelpers;
12
use NotificationChannels\OneSignal\Traits\Categories\AttachmentHelpers;
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
    public static function create($body = '')
27
    {
28
        return new static($body);
29
    }
30
31
    /**
32
     * @param string $body
33
     */
34
    public function __construct($body = '')
35
    {
36
        $this->setBody($body);
37
    }
38 1
39
    /**
40 1
     * Set the message body.
41
     *
42
     * @param mixed $value
43
     *
44
     * @return $this
45
     */
46 20
    public function setBody($value)
47
    {
48 20
        return $this->setParameter('contents', $this->parseValueToArray($value));
49 20
    }
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 1
63
    /**
64
     * Set the message template_id.
65
     *
66
     * @param string $value
67
     *
68
     * @return $this
69
     */
70
    public function setTemplate($value)
71
    {
72 6
        Arr::forget($this->payload, 'contents');
73
74 6
        return $this->setParameter('template_id', $value);
75
    }
76 6
77
    /**
78
     * @param mixed $value
79
     *
80
     * @return array
81
     */
82
    protected function parseValueToArray($value)
83
    {
84
        return (is_array($value)) ? $value : ['en' => $value];
85
    }
86 6
87
    /**
88 6
     * Set additional data.
89
     *
90 6
     * @param string $key
91
     * @param mixed  $value
92
     *
93
     * @return $this
94
     */
95
    public function setData(string $key, $value)
96
    {
97
        return $this->setParameter("data.{$key}", $value);
98
    }
99
100 6
    /**
101
     * Set parameters.
102 6
     *
103
     * @param string $key
104 6
     * @param mixed  $value
105
     *
106
     * @return $this
107
     */
108
    public function setParameter(string $key, $value)
109
    {
110
        Arr::set($this->payload, $key, $value);
111
112
        return $this;
113
    }
114 1
115
    /**
116 1
     * Get parameters.
117 1
     *
118
     * @param string $key
119
     * @param mixed  $default
120
     *
121
     * @return mixed
122
     */
123
    public function getParameter(string $key, $default = null)
124
    {
125
        return Arr::get($this->payload, $key, $default);
126
    }
127 1
128
    /**
129 1
     * @return array
130 1
     */
131
    public function toArray()
132
    {
133
        return $this->payload;
134
    }
135
}
136