YunPianAgent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 79.59 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 39
loc 49
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A sendContentSms() 14 14 1
A sendVoiceCode() 14 14 1
A setResult() 11 11 2

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 Toplan\PhpSms;
4
5
/**
6
 * Class YunPianAgent
7
 *
8
 * @property string $apikey
9
 */
10
class YunPianAgent extends Agent implements ContentSms, VoiceCode
11
{
12
    protected $headers = [
13
        'Accept:application/json;charset=utf-8',
14
        'Content-Type:application/x-www-form-urlencoded;charset=utf-8',
15
    ];
16
17 View Code Duplication
    public function sendContentSms($to, $content)
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...
18
    {
19
        $url = 'https://sms.yunpian.com/v1/sms/send.json';
20
        $params = $this->params([
21
            'apikey' => $this->apikey,
22
            'mobile' => $to,
23
            'text'   => $content,
24
        ]);
25
        $result = $this->curlPost($url, [], [
26
            CURLOPT_HTTPHEADER => $this->headers,
27
            CURLOPT_POSTFIELDS => http_build_query($params),
28
        ]);
29
        $this->setResult($result);
30
    }
31
32 View Code Duplication
    public function sendVoiceCode($to, $code)
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...
33
    {
34
        $url = 'https://voice.yunpian.com/v1/voice/send.json';
35
        $params = $this->params([
36
            'apikey' => $this->apikey,
37
            'mobile' => $to,
38
            'code'   => $code,
39
        ]);
40
        $result = $this->curlPost($url, [], [
41
            CURLOPT_HTTPHEADER => $this->headers,
42
            CURLOPT_POSTFIELDS => http_build_query($params),
43
        ]);
44
        $this->setResult($result);
45
    }
46
47 View Code Duplication
    protected function setResult($result)
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...
48
    {
49
        if ($result['request']) {
50
            $this->result(Agent::INFO, $result['response']);
51
            $result = json_decode($result['response'], true);
52
            $this->result(Agent::SUCCESS, $result['code'] === 0);
53
            $this->result(Agent::CODE, $result['code']);
54
        } else {
55
            $this->result(Agent::INFO, 'request failed');
56
        }
57
    }
58
}
59