Completed
Pull Request — master (#104)
by Tyler
02:22
created

Pushover::getSound()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 4
nop 0
1
<?php
2
3
namespace Spatie\Backup\Notifications\Senders;
4
5
use Illuminate\Contracts\Config\Repository;
6
use Spatie\Backup\Notifications\BaseSender;
7
8
class Pushover extends BaseSender
9
{
10
    /** @var array */
11
    protected $config;
12
13
    /**
14
     * @param Repository $config
15
     */
16
    public function __construct(Repository $config)
17
    {
18
        $this->config = $config->get('laravel-backup.notifications.pushover');
0 ignored issues
show
Documentation Bug introduced by
It seems like $config->get('laravel-ba...otifications.pushover') of type * is incompatible with the declared type array of property $config.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
19
    }
20
21
    /**
22
     * Sends the message to the Pushover API
23
     * @return void
24
     */
25
    public function send()
26
    {
27
        curl_setopt_array($ch = curl_init(), [
28
            CURLOPT_URL => 'https://api.pushover.net/1/messages.json',
29
            CURLOPT_POSTFIELDS => [
30
                'token' => $this->config['token'],
31
                'user' => $this->config['user'],
32
                'title' => $this->subject,
33
                'message' => $this->message,
34
                'sound' => $this->getSound(),
35
            ],
36
            CURLOPT_SAFE_UPLOAD => true,
37
        ]);
38
        curl_exec($ch);
39
        curl_close($ch);
40
    }
41
42
    /**
43
     * Returns the proper sound for the notification type according to the config file
44
     * @return string The sound string to use
45
     */
46
    private function getSound()
47
    {
48
        $sounds = isset($this->config['sounds']) ? $this->config['sounds'] : ['success' => 'pushover', 'error' => 'siren'];
49
50
        $sound = $this->type === static::TYPE_SUCCESS ? $sounds['success'] : $sounds['error'];
51
52
        return $sound;
53
    }
54
55
}
56