Completed
Push — master ( daa55e...283203 )
by lan tian
9s
created

YunPianAgent::sendTemplateSms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 3
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
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
    public function sendSms($to, $content, $tempId, array $data)
18
    {
19
        $this->sendContentSms($to, $content);
20
    }
21
22 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...
23
    {
24
        $url = 'https://sms.yunpian.com/v1/sms/send.json';
25
        $params = [
26
            'apikey' => $this->apikey,
27
            'mobile' => $to,
28
            'text'   => $content,
29
        ];
30
        $result = $this->curl($url, true, [
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array(CURLOPT_HTTPHEADER...p_build_query($params)) is of type array<integer,array|string>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
31
            CURLOPT_HTTPHEADER => $this->headers,
32
            CURLOPT_POSTFIELDS => http_build_query($params),
33
        ]);
34
        $this->setResult($result);
35
    }
36
37 View Code Duplication
    public function voiceVerify($to, $code, $tempId, array $data)
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...
38
    {
39
        $url = 'https://voice.yunpian.com/v1/voice/send.json';
40
        $params = [
41
            'apikey' => $this->apikey,
42
            'mobile' => $to,
43
            'code'   => $code,
44
        ];
45
        $result = $this->curl($url, true, [
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
array(CURLOPT_HTTPHEADER...p_build_query($params)) is of type array<integer,array|string>, but the function expects a boolean.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
            CURLOPT_HTTPHEADER => $this->headers,
47
            CURLOPT_POSTFIELDS => http_build_query($params),
48
        ]);
49
        $this->setResult($result);
50
    }
51
52 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...
53
    {
54
        if ($result['request']) {
55
            $this->result(Agent::INFO, $result['response']);
56
            $result = json_decode($result['response'], true);
57
            $this->result(Agent::SUCCESS, $result['code'] === 0);
58
            $this->result(Agent::CODE, $result['code']);
59
        } else {
60
            $this->result(Agent::INFO, 'request failed');
61
        }
62
    }
63
}
64