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