VoiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 67
Duplicated Lines 25.37 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 2
cbo 2
dl 17
loc 67
ccs 0
cts 35
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getRequiredOptions() 17 17 3
A getUrl() 0 6 1
A getRequestPayload() 0 10 1
A getName() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Huying\Sms\RongLian;
4
5
use GuzzleHttp\Exception\GuzzleException;
6
use Huying\Sms\AbstractProvider;
7
use Huying\Sms\Message;
8
use Huying\Sms\ProviderException;
9
use Psr\Http\Message\ResponseInterface;
10
11
/**
12
 * 容联短信平台接口实现
13
 *
14
 * Class Provider
15
 */
16
class VoiceProvider extends Provider
17
{
18
    /**
19
     * 返回短信接口必须的参数
20
     * @param $key
21
     * @return array
22
     */
23 View Code Duplication
    protected function getRequiredOptions($key)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        if ($key == self::PROVIDER_OPTIONS) {
26
            return [
27
                'accountSid',
28
                'authToken',
29
                'appId',
30
            ];
31
        } elseif ($key == self::MESSAGE_OPTIONS) {
32
            return [
33
                'recipients',
34
                'data',
35
            ];
36
        } else {
37
            return []; // @codeCoverageIgnore
38
        }
39
    }
40
41
    /**
42
     * 返回请求链接
43
     *
44
     * @param Message $message
45
     * @return string
46
     * @throws \RuntimeException
47
     */
48
    protected function getUrl(Message $message)
49
    {
50
        return $this->restUrl.'/'.$this->softVersion
51
            .'/Accounts/'.$this->accountSid
52
            .'/Calls/VoiceVerify?sig='.strtoupper(md5($this->accountSid.$this->authToken.$this->getTimestamp()));
53
    }
54
55
    /**
56
     * 返回请求短信接口时的 payload
57
     *
58
     * @param Message $message
59
     * @return string
60
     * @throws \RuntimeException
61
     */
62
    protected function getRequestPayload(Message $message)
63
    {
64
        $recipients = implode(',', $message->getRecipients());
65
        $data = $message->getData();
66
67
        return json_encode([
68
            'to' => $recipients,
69
            'appId' => $this->appId,
70
        ] + $data);
71
    }
72
73
    /**
74
     * 获取短信供应商名称
75
     *
76
     * @return string
77
     */
78
    public function getName()
79
    {
80
        return 'RongLian';
81
    }
82
}
83