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 (#24)
by
unknown
02:34 queued 15s
created

PushbulletMessage::toAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace NotificationChannels\Pushbullet;
4
5
use NotificationChannels\Pushbullet\Targets\Targetable;
6
7
class PushbulletMessage
8
{
9
    const TYPE_NOTE = 'note';
10
    const TYPE_LINK = 'link';
11
12
    /**
13
     * Type of message (currently: note or link).
14
     *
15
     * @var string
16
     */
17
    public $type = 'note';
18
19
    /** @var \NotificationChannels\Pushbullet\Targets\Targetable */
20
    protected $target;
21
22
    /**
23
     * Notification title.
24
     *
25
     * @var string
26
     */
27
    public $title;
28
29
    /**
30
     * Notification message.
31
     *
32
     * @var string
33
     */
34
    public $message;
35
36
    /**
37
     * Url if notification is of link type.
38
     *
39
     * @var string
40
     */
41
    public $url;
42
43
    /**
44
     * Push notification to all devices.
45
     *
46
     * @var bool
47
     */
48
    public $toAll = false;
49
50
    /**
51
     * @param string $message
52
     *
53
     * @return static
54
     */
55
    public static function create($message)
56
    {
57
        return new static($message);
58
    }
59
60
    /**
61
     * @param string $message
62
     */
63
    public function __construct($message)
64
    {
65
        $this->message = $message;
66
    }
67
68
    /**
69
     * @param  \NotificationChannels\Pushbullet\Targets\Targetable  $targetable
70
     *
71
     * @return $this
72
     */
73
    public function target(Targetable $targetable)
74
    {
75
        $this->target = $targetable;
76
77
        return $this;
78
    }
79
80
    /**
81
     * Specify that notification is of `note` type.
82
     *
83
     * @return $this
84
     */
85
    public function note()
86
    {
87
        $this->type = static::TYPE_NOTE;
88
89
        return $this;
90
    }
91
92
    /**
93
     * Specify that notification is of `link` type.
94
     *
95
     * @return $this
96
     */
97
    public function link()
98
    {
99
        $this->type = static::TYPE_LINK;
100
101
        return $this;
102
    }
103
104
    /**
105
     * Set notification title.
106
     *
107
     * @param  string  $title
108
     *
109
     * @return $this
110
     */
111
    public function title($title)
112
    {
113
        $this->title = $title;
114
115
        return $this;
116
    }
117
118
    /**
119
     * Set notification message.
120
     *
121
     * @param  string  $message
122
     *
123
     * @return $this
124
     */
125
    public function message($message)
126
    {
127
        $this->message = $message;
128
129
        return $this;
130
    }
131
132
    /**
133
     * Set notification url (if notification is of `link` type).
134
     *
135
     * @param  string  $url
136
     *
137
     * @return $this
138
     */
139
    public function url($url)
140
    {
141
        $this->url = $url;
142
143
        return $this;
144
    }
145
146
    /**
147
     * @param mixed $toAll
148
     *
149
     * @return PushbulletMessage
150
     */
151
    public function toAll($toAll = true)
152
    {
153
        $this->toAll = $toAll;
154
155
        return $this;
156
    }
157
158
    /**
159
     * @return mixed
160
     */
161
    public function getToAll()
162
    {
163
        return $this->toAll;
164
    }
165
166
    /**
167
     * Get array representation of message for Pushbullet client.
168
     *
169
     * @return array
170
     */
171
    public function toArray()
172
    {
173
        $payload = [
174
            'type' => $this->type,
175
            'title' => $this->title,
176
            'body' => $this->message,
177
        ];
178
179
        if (! $this->toAll) {
180
            $payload['target'] = $this->target->getTarget();
181
        }
182
183
        if ($this->type === static::TYPE_LINK) {
184
            $payload['url'] = $this->url;
185
        }
186
187
        return $payload;
188
    }
189
}
190