GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

SmsapiClient::sendVms()   F
last analyzed

Complexity

Conditions 13
Paths 3072

Size

Total Lines 43
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 182

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 43
ccs 0
cts 40
cp 0
rs 2.7716
cc 13
eloc 28
nc 3072
nop 1
crap 182

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\Smsapi;
4
5
use SMSApi\Client;
6
use SMSApi\Proxy\Proxy;
7
use SMSApi\Api\MmsFactory;
8
use SMSApi\Api\SmsFactory;
9
use SMSApi\Api\VmsFactory;
10
use SMSApi\Api\Response\Response;
11
12
class SmsapiClient
13
{
14
    /**
15
     * @var Client
16
     */
17
    protected $client;
18
19
    /**
20
     * @var array
21
     */
22
    protected $defaults;
23
24
    /**
25
     * @var Proxy
26
     */
27
    protected $proxy;
28
29
    /**
30
     * @param Client     $client
31
     * @param array      $defaults
32
     * @param Proxy|null $proxy
33
     */
34 1
    public function __construct(Client $client, array $defaults = [], Proxy $proxy = null)
35
    {
36 1
        $this->client = $client;
37 1
        $this->defaults = $defaults;
38 1
        $this->proxy = $proxy;
39 1
    }
40
41
    /**
42
     * @param  SmsapiMessage $message
43
     * @return Response
44
     */
45 1
    public function send(SmsapiMessage $message)
46
    {
47 1
        if ($message instanceof SmsapiSmsMessage) {
48 1
            return $this->sendSms($message);
49
        } elseif ($message instanceof SmsapiMmsMessage) {
50
            return $this->sendMms($message);
51
        } elseif ($message instanceof SmsapiVmsMessage) {
52
            return $this->sendVms($message);
53
        }
54
    }
55
56
    /**
57
     * @param  SmsapiSmsMessage $message
58
     * @return Response
59
     */
60 1
    public function sendSms(SmsapiSmsMessage $message)
61
    {
62 1
        $data = $message->data + $this->defaults;
63 1
        $sms = (new SmsFactory($this->proxy, $this->client))->actionSend();
64 1
        if (isset($data['content'])) {
65 1
            $sms->setText($data['content']);
66 1
        }
67 1
        if (isset($data['template'])) {
68
            $sms->setTemplate($data['template']);
69
        }
70 1
        if (isset($data['to'])) {
71 1
            $sms->setTo($data['to']);
72 1
        }
73 1
        if (isset($data['group'])) {
74
            $sms->setGroup($data['group']);
75
        }
76 1
        if (isset($data['from'])) {
77
            $sms->setSender($data['from']);
78
        }
79 1
        if (isset($data['fast'])) {
80
            $sms->setFast($data['fast']);
81
        }
82 1
        if (isset($data['flash'])) {
83
            $sms->setFlash($data['flash']);
84
        }
85 1
        if (isset($data['encoding'])) {
86
            $sms->setEncoding($data['encoding']);
87
        }
88 1
        if (isset($data['normalize'])) {
89
            $sms->setNormalize($data['normalize']);
90
        }
91 1
        if (isset($data['nounicode'])) {
92
            $sms->setNoUnicode($data['nounicode']);
93
        }
94 1
        if (isset($data['single'])) {
95
            $sms->setSingle($data['single']);
96
        }
97 1
        if (isset($data['date'])) {
98
            $sms->setDateSent($data['date']);
99
        }
100 1
        if (isset($data['notify_url'])) {
101
            $sms->setNotifyUrl($data['notify_url']);
102
        }
103 1
        if (isset($data['partner'])) {
104
            $sms->setPartner($data['partner']);
105
        }
106 1
        if (isset($data['test'])) {
107
            $sms->setTest($data['test']);
108
        }
109
110 1
        return $sms->execute();
111
    }
112
113
    /**
114
     * @param  SmsapiMmsMessage $message
115
     * @return Response
116
     */
117
    public function sendMms(SmsapiMmsMessage $message)
118
    {
119
        $data = $message->data + $this->defaults;
120
        $mms = (new MmsFactory($this->proxy, $this->client))->actionSend();
121
        $mms->setSubject($data['subject']);
122
        $mms->setSmil($data['smil']);
123
        if (isset($data['to'])) {
124
            $mms->setTo($data['to']);
125
        }
126
        if (isset($data['group'])) {
127
            $mms->setGroup($data['group']);
128
        }
129
        if (isset($data['date'])) {
130
            $mms->setDateSent($data['date']);
131
        }
132
        if (isset($data['notify_url'])) {
133
            $mms->setNotifyUrl($data['notify_url']);
134
        }
135
        if (isset($data['partner'])) {
136
            $mms->setPartner($data['partner']);
137
        }
138
        if (isset($data['test'])) {
139
            $mms->setTest($data['test']);
140
        }
141
142
        return $mms->execute();
143
    }
144
145
    /**
146
     * @param  SmsapiVmsMessage $message
147
     * @return Response
148
     */
149
    public function sendVms(SmsapiVmsMessage $message)
150
    {
151
        $data = $message->data + $this->defaults;
152
        $vms = (new VmsFactory($this->proxy, $this->client))->actionSend();
153
        if (isset($data['file'])) {
154
            $vms->setFile($data['file']);
155
        }
156
        if (isset($data['tts'])) {
157
            $vms->setTts($data['tts']);
158
            if (isset($data['tts_lector'])) {
159
                $vms->setTtsLector($data['tts_lector']);
160
            }
161
        }
162
        if (isset($data['to'])) {
163
            $vms->setTo($data['to']);
164
        }
165
        if (isset($data['group'])) {
166
            $vms->setGroup($data['group']);
167
        }
168
        if (isset($data['from'])) {
169
            $vms->setFrom($data['from']);
170
        }
171
        if (isset($data['tries'])) {
172
            $vms->setTry($data['tries']);
173
        }
174
        if (isset($data['interval'])) {
175
            $vms->setInterval($data['interval']);
176
        }
177
        if (isset($data['date'])) {
178
            $vms->setDateSent($data['date']);
179
        }
180
        if (isset($data['notify_url'])) {
181
            $vms->setNotifyUrl($data['notify_url']);
0 ignored issues
show
Bug introduced by
The method setNotifyUrl() does not seem to exist on object<SMSApi\Api\Action\Vms\Send>.

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...
182
        }
183
        if (isset($data['partner'])) {
184
            $vms->setPartner($data['partner']);
185
        }
186
        if (isset($data['test'])) {
187
            $vms->setTest($data['test']);
188
        }
189
190
        return $vms->execute();
191
    }
192
}
193