Completed
Push — master ( 56566c...f8ca6f )
by Muhammad
06:54
created

GammuChannel::gammuExceptions()   C

Complexity

Conditions 14
Paths 18

Size

Total Lines 37
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 210

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 37
ccs 0
cts 30
cp 0
rs 5.0864
cc 14
eloc 19
nc 18
nop 2
crap 210

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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