Completed
Push — master ( e1ad2f...7f0e8c )
by
unknown
09:06 queued 02:12
created

GammuChannel::getMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 0
cts 5
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 0
crap 6
1
<?php
2
3
namespace NotificationChannels\Gammu;
4
5
use Illuminate\Notifications\Notification;
6
use Illuminate\Contracts\Config\Repository;
7
use NotificationChannels\Gammu\Drivers\DbDriver;
8
use NotificationChannels\Gammu\Drivers\ApiDriver;
9
use NotificationChannels\Gammu\Drivers\RedisDriver;
10
use NotificationChannels\Gammu\Exceptions\CouldNotSendNotification;
11
12
class GammuChannel
13
{
14
    protected $config;
15
16
    protected $dbDriver;
17
18
    protected $apiDriver;
19
20
    protected $redisDriver;
21
22
    private $method;
23
24
    public function __construct(
25
        Repository $config, DbDriver $dbDriver, ApiDriver $apiDriver, RedisDriver $redisDriver
26
    ) {
27
        $this->config = $config;
28
        $this->dbDriver = $dbDriver;
29
        $this->apiDriver = $apiDriver;
30
        $this->redisDriver = $redisDriver;
31
    }
32
33
    /**
34
     * Send the given notification.
35
     *
36
     * @param mixed $notifiable
37
     * @param $notification
38
     */
39
    public function send($notifiable, Notification $notification)
40
    {
41
        $payload = $notification->toGammu($notifiable);
0 ignored issues
show
Bug introduced by
The method toGammu() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
42
43
        $destination = $payload->destination;
44
        $content = $payload->content;
45
        $sender = $payload->sender;
46
        $callback = $payload->callback;
47
        $channel = $payload->channel;
48
49
        $this->getMethod();
50
51
        switch ($this->method) {
52
            case 'db':
53
                $this->dbDriver->send($destination, $content, $sender);
54
                break;
55
            case 'api':
56
                $this->apiDriver->send($destination, $content, $sender, $callback);
57
                break;
58
            case 'redis':
59
                $this->redisDriver->send($destination, $content, $channel, $sender, $callback);
60
                break;
61
            default:
62
                throw CouldNotSendNotification::invalidMethodProvided();
63
        }
64
    }
65
66
    private function getMethod()
67
    {
68
        $this->method = $this->config->get('services.gammu.method');
69
70
        if (empty($this->method)) {
71
            throw CouldNotSendNotification::methodNotProvided();
72
        }
73
74
        return $this;
75
    }
76
}
77