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:33 queued 04:01
created

OneSignalMessage   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 91.67%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 10
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 112
ccs 22
cts 24
cp 0.9167
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A url() 0 4 1
A create() 0 4 1
A __construct() 0 4 1
A body() 0 10 2
A subject() 0 10 2
A setData() 0 4 1
A setParameter() 0 6 1
A toArray() 0 4 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
    use OneSignalHelpers;
11
12
    /** @var array */
13
    protected $data = [];
14
15
    /** @var array */
16
    protected $payload = [];
17
18
    /**
19
     * @param string $body
20
     *
21
     * @return static
22
     */
23 1
    public static function create($body = '')
24
    {
25 1
        return new static($body);
26
    }
27
28
    /**
29
     * @param string $body
30
     */
31 20
    public function __construct($body = '')
32
    {
33 20
        $this->body($body);
34 20
    }
35
36
    /**
37
     * Set the message body.
38
     *
39
     * @param string $value
40
     *
41
     * @return $this
42
     */
43 20
    public function body($value)
44
    {
45 20
        if (is_array($value)) {
46
            $this->setParameter('contents', $value);
47
        } else {
48 20
            $this->setParameter('contents', ['en' => $value]);
49
        }
50
51 20
        return $this;
52
    }
53
54
    /**
55
     * Set the message subject.
56
     *
57
     * @param string $value
58
     *
59
     * @return $this
60
     */
61 6
    public function subject($value)
62
    {
63 6
        if (is_array($value)) {
64
            $this->setParameter('headings', $value);
65
        } else {
66 6
            $this->setParameter('headings', ['en' => $value]);
67
        }
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
     * Set additional data.
86
     *
87
     * @param string $key
88
     * @param mixed $value
89
     *
90
     * @return $this
91
     */
92 1
    public function setData(string $key, $value)
93
    {
94 1
        return $this->setParameter("data.{$key}", $value);
95
    }
96
97
    /**
98
     * Set additional parameters.
99
     *
100
     * @param string $key
101
     * @param mixed $value
102
     *
103
     * @return $this
104
     */
105 20
    public function setParameter(string $key, $value)
106
    {
107 20
        Arr::set($this->payload, $key, $value);
108
109 20
        return $this;
110
    }
111
112
    /**
113
     * @return array
114
     */
115 20
    public function toArray()
116
    {
117 20
        return $this->payload;
118
    }
119
}
120