IhuyiAgent::voiceVerify()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 3
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 4
crap 2
1
<?php
2
3
namespace zacksleo\PhpSms;
4
5
use Toplan\PhpSms\Agent;
6
7
/**
8
 * Class 互亿无线短信接口
9
 * @package Toplan\PhpSms
10
 * @property string $sendUrl
11
 * @property string $apiKey
12
 * @property string $secretKey
13
 * @property string $smsFreeSignName
14
 * @property string $calledShowNum
15
 */
16
class IhuyiAgent extends Agent
17
{
18
    public function sendSms($to, $content, $tempId, array $tempData)
19
    {
20
        $this->sendContentSms($to, $content);
21
    }
22
23
    public function voiceVerify($to, $code, $tempId, array $tempData)
0 ignored issues
show
Unused Code introduced by
The parameter $to is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $code is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tempId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tempData is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25
    }
26
27
    public function sendTemplateSms($to, $tempId, array $tempData)
0 ignored issues
show
Unused Code introduced by
The parameter $to is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tempId is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $tempData is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
    {
29
    }
30
31
    public function sendContentSms($to, $content)
32
    {
33
        $to = ltrim($to, '+');
34
        //如果是中国的手机号,去掉86,并使用国内短信网关
35
        if (preg_match('/^86\s[1][34578][0-9]{9}$/', $to)) {
36
            $to = substr($to, -11, 11);
37
        } elseif (preg_match('/^[1][34578][0-9]{9}$/', $to)) {
38
            $this->sendUrl = 'http://106.ihuyi.cn/webservice/sms.php?method=Submit';
39
        } else {
40
            $this->sendUrl = 'http://api.isms.ihuyi.com/webservice/isms.php?method=Submit';
41
        }
42
        $params = [
43
            'mobile' => $to,
44
            'content' => $content,
45
        ];
46
        $this->request($params);
47
    }
48
49
    protected function request(array $params)
50
    {
51
        $sendUrl = $this->sendUrl ?: 'http://106.ihuyi.cn/webservice/sms.php?method=Submit';
52
        $params = $this->createParams($params);
53
        $result = $this->curl($sendUrl, $params, true);
0 ignored issues
show
Documentation introduced by
$sendUrl is of type string, 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...
Unused Code introduced by
The call to IhuyiAgent::curl() has too many arguments starting with $params.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
54
        $this->setResult($result);
55
    }
56
57
    protected function createParams(array $params)
58
    {
59
        $params = array_merge([
60
            'account' => $this->apiKey,
61
            'password' => $this->secretKey,
62
        ], $params);
63
        return $params;
64
    }
65
66
    protected function setResult($result)
67
    {
68
        if (!$result['request']) {
69
            $this->result(Agent::SUCCESS, false);
70
        } else {
71
            $return = @simplexml_load_string($result['response']);
72
            $this->result(Agent::SUCCESS, $return->code == 2);
73
            $this->result(Agent::CODE, $return->code);
74
            $this->result(Agent::INFO, $return->msg);
75
        }
76
    }
77
}
78