YunTongXunAgent   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendTemplateSms() 0 6 1
A sendVoiceCode() 0 11 4
A rest() 0 8 1
B setResult() 0 18 5
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
use REST;
6
7
/**
8
 * Class YunTongXunAgent
9
 *
10
 * @property string $serverIP
11
 * @property string $serverPort
12
 * @property string $accountSid
13
 * @property string $accountToken
14
 * @property string $appId
15
 * @property int    $playTimes
16
 * @property string $displayNum
17
 */
18
class YunTongXunAgent extends Agent implements TemplateSms, VoiceCode
19
{
20
    public function sendTemplateSms($to, $tempId, array $data)
21
    {
22
        $data = array_values($data);
23
        $result = $this->rest()->sendTemplateSMS($to, $data, $tempId);
0 ignored issues
show
Bug introduced by
It seems like $to defined by parameter $to on line 20 can also be of type array; however, REST::sendTemplateSMS() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
24
        $this->setResult($result);
25
    }
26
27
    public function sendVoiceCode($to, $code)
28
    {
29
        $playTimes = intval($this->playTimes ?: 3);
30
        $displayNum = $this->displayNum ?: null;
31
        $lang = $this->params('lang') ?: 'zh';
32
        $respUrl = $this->params('respUrl');
33
        $userData = $this->params('userData');
34
        $welcomePrompt = $this->params('welcomePrompt');
35
        $result = $this->rest()->voiceVerify($code, $playTimes, $to, $displayNum, $respUrl, $lang, $userData, $welcomePrompt);
36
        $this->setResult($result);
37
    }
38
39
    protected function rest()
40
    {
41
        $rest = new REST($this->serverIP, $this->serverPort, '2013-12-26', 'json');
42
        $rest->setAccount($this->accountSid, $this->accountToken);
43
        $rest->setAppId($this->appId);
44
45
        return $rest;
46
    }
47
48
    protected function setResult($result)
49
    {
50
        if (!$result) {
51
            return;
52
        }
53
        $code = $info = (string) $result->statusCode;
54
        $success = $code === '000000';
55
        if (isset($result->statusMsg)) {
56
            $info = (string) $result->statusMsg;
57
        } elseif (isset($result->TemplateSMS)) {
58
            $info = 'smsSid:' . $result->TemplateSMS->smsMessageSid;
59
        } elseif (isset($result->VoiceVerify)) {
60
            $info = 'callSid:' . $result->VoiceVerify->callSid;
61
        }
62
        $this->result(Agent::SUCCESS, $success);
63
        $this->result(Agent::CODE, $code);
64
        $this->result(Agent::INFO, $info);
65
    }
66
}
67