Completed
Push — master ( 30fe91...a411db )
by Muhammad
09:22 queued 05:05
created

GammuChannel::getMethod()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 4
cts 5
cp 0.8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
crap 2.032
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\Exceptions\CouldNotSendNotification;
10
11
class GammuChannel
12
{
13
    protected $config;
14
15
    protected $dbDriver;
16
17
    protected $apiDriver;
18
19
    private $method;
20
21 2
    public function __construct(
22
        Repository $config, DbDriver $dbDriver, ApiDriver $apiDriver
23
    ) {
24 2
        $this->config = $config;
25 2
        $this->dbDriver = $dbDriver;
26 2
        $this->apiDriver = $apiDriver;
27 2
    }
28
29
    /**
30
     * Send the given notification.
31
     *
32
     * @param mixed $notifiable
33
     * @param $notification
34
     */
35 2
    public function send($notifiable, Notification $notification)
36
    {
37 2
        $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...
38
39 2
        $destination = $payload->destination;
40 2
        $content = $payload->content;
41 2
        $sender = $payload->sender;
42 2
        $callback = $payload->callback;
43
44 2
        $this->getMethod();
45
46 2
        switch ($this->method) {
47 2
            case 'db':
48 1
                $this->dbDriver->send($destination, $content, $sender);
49 1
                break;
50 1
            case 'api':
51 1
                $this->apiDriver->send($destination, $content, $sender, $callback);
52 1
                break;
53
            default:
54
                throw CouldNotSendNotification::invalidMethodProvided();
55
        }
56 2
    }
57
58 2
    private function getMethod()
59
    {
60 2
        $this->method = $this->config->get('services.gammu.method');
61
62 2
        if (empty($this->method)) {
63
            throw CouldNotSendNotification::methodNotProvided();
64
        }
65
66 2
        return $this;
67
    }
68
}
69