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
01:54
created

OneSignalMessage::subject()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 9
ccs 4
cts 5
cp 0.8
rs 9.6666
cc 2
eloc 6
nc 2
nop 1
crap 2.032
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
12
13
    /** @var array */
14
    protected $data = [];
15
16
17
    /** @var array */
18
    protected $payload = [];
19
20
    /**
21
     * @param string $body
22
     *
23
     * @return static
24
     */
25 1
    public static function create($body = '')
26
    {
27 1
        return new static($body);
28
    }
29
30
    /**
31
     * @param string $body
32
     */
33 20
    public function __construct($body = '')
34
    {
35 20
       $this->body($body);
36 20
    }
37
38
    /**
39
     * Set the message body.
40
     *
41
     * @param string $value
42
     *
43
     * @return $this
44
     */
45 20
    public function body($value)
46
    {
47 20
        if(is_array($value)){
48
            $this->setParameter('contents',$value);
49
        } else {
50 20
            $this->setParameter('contents',['en' => $value]);
51
        }
52 20
        return $this;
53
    }
54
55
    /**
56
     * Set the message subject.
57
     *
58
     * @param string $value
59
     *
60
     * @return $this
61
     */
62 6
    public function subject($value)
63
    {
64 6
        if(is_array($value)){
65
            $this->setParameter('headings',$value);
66
        } else {
67 6
            $this->setParameter('headings',['en' => $value]);
68
        }
69 6
        return $this;
70
    }
71
72
    /**
73
     * Set the message url.
74
     *
75
     * @param string $value
76
     *
77
     * @return $this
78
     */
79 6
    public function url($value)
80
    {
81 6
       return $this->setUrl($value);
82
    }
83
84
85
    /**
86
     * Set additional data.
87
     *
88
     * @param string $key
89
     * @param string $value
90
     *
91
     * @return $this
92
     */
93 1
    public function setData($key, $value)
94
    {
95 1
        $this->data[$key] = $value;
96
97 1
        return $this;
98
    }
99
100
    /**
101
     * Set additional parameters.
102
     *
103
     * @param string $key
104
     * @param mixed $value
105
     *
106
     * @return $this
107
     */
108 20
    public function setParameter(string $key, $value)
109
    {
110 20
        $this->payload[$key] = $value;
111
112 20
        return $this;
113
    }
114
115
116
117
    /**
118
     * @return array
119
     */
120 20
    public function toArray()
121
    {
122
123 20
        foreach ($this->data as $data => $value) {
124 1
            Arr::set($this->payload, 'data.'.$data, $value);
125
        }
126
127 20
        return $this->payload;
128
    }
129
}
130