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.
Completed
Push — master ( 3df939...d640e4 )
by Mateusz
01:51
created

SmsapiClient   B

Complexity

Total Complexity 41

Size/Duplication

Total Lines 181
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 31.18%

Importance

Changes 0
Metric Value
wmc 41
c 0
b 0
f 0
lcom 1
cbo 9
dl 0
loc 181
ccs 29
cts 93
cp 0.3118
rs 8.2769

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A send() 0 10 4
F sendSms() 0 52 16
C sendMms() 0 27 7
F sendVms() 0 43 13

How to fix   Complexity   

Complex Class

Complex classes like SmsapiClient often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SmsapiClient, and based on these observations, apply Extract Interface, too.

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
        }
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
        }
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