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

OneSignalMessage::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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
11
    use OneSignalHelpers;
12
13
    /** @var array */
14
    protected $data = [];
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 20
    public function __construct($body = '')
33
    {
34 20
        $this->body($body);
35 20
    }
36
37
    /**
38
     * Set the message body.
39
     *
40
     * @param mixed $value
41
     *
42
     * @return $this
43
     */
44 20
    public function body($value)
45
    {
46 20
        return $this->setParameter('contents', $this->parseValueToArray($value));
47
    }
48
49
    /**
50
     * Set the message subject.
51
     *
52
     * @param mixed $value
53
     *
54
     * @return $this
55
     */
56 6
    public function subject($value)
57
    {
58 6
        return $this->setParameter('headings',$this->parseValueToArray($value));
59
    }
60
61
    /**
62
     * @param mixed $value
63
     *
64
     * @return array
65
     */
66 20
    protected function parseValueToArray($value){
67 20
        return (is_array($value)) ? $value : ['en' => $value];
68
    }
69
    /**
70
     * Set the message url.
71
     *
72
     * @param string $value
73
     *
74
     * @return $this
75
     */
76 6
    public function url($value)
77
    {
78 6
        return $this->setUrl($value);
79
    }
80
81
    /**
82
     * Set additional data.
83
     *
84
     * @param string $key
85
     * @param mixed  $value
86
     *
87
     * @return $this
88
     */
89 1
    public function setData(string $key, $value)
90
    {
91 1
        return $this->setParameter("data.{$key}", $value);
92
    }
93
94
    /**
95
     * Set additional parameters.
96
     *
97
     * @param string $key
98
     * @param mixed  $value
99
     *
100
     * @return $this
101
     */
102 20
    public function setParameter(string $key, $value)
103
    {
104 20
        Arr::set($this->payload, $key, $value);
105
106 20
        return $this;
107
    }
108
109
    /**
110
     * @return array
111
     */
112 20
    public function toArray()
113
    {
114 20
        return $this->payload;
115
    }
116
}
117