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:47
created

OneSignalMessage::setParameter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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