Completed
Pull Request — master (#15)
by lan tian
02:34
created

LogAgent::sendSms()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3.0987

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 15
ccs 7
cts 9
cp 0.7778
rs 9.4286
cc 3
eloc 8
nc 3
nop 4
crap 3.0987
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class LogAgent
7
 * 测试|寄生 代理器
8
 *
9
 * @property string $sendSms
10
 * @property string $voiceVerify
11
 */
12
class LogAgent extends Agent
13
{
14 21
    public function sendSms($tempId, $to, array $data, $content)
15
    {
16
        //作为寄生代理器发送短信
17 21
        if (is_callable($this->sendSms)) {
18
            call_user_func_array($this->sendSms, [$this, $to, $tempId, $data, $content]);
19
20
            return;
21
        }
22
        //作为测试代理器
23 21
        if ($content) {
24 18
            $this->sendContentSms($to, $content);
25 18
        } else {
26 3
            $this->sendTemplateSms($tempId, $to, $data);
27
        }
28 21
    }
29
30 18
    public function sendContentSms($to, $content)
31
    {
32 18
        $this->result['success'] = true;
33 18
        $this->result['info'] = 'send content sms success';
34 18
    }
35
36 3
    public function sendTemplateSms($tempId, $to, array $data)
37
    {
38 3
        $this->result['success'] = true;
39 3
        $this->result['info'] = 'send template sms success';
40 3
    }
41
42 3
    public function voiceVerify($to, $code)
43
    {
44
        //作为寄生代理器发送语音验证码
45 3
        if (is_callable($this->voiceVerify)) {
46
            call_user_func_array($this->voiceVerify, [$this, $to, $code]);
47
48
            return;
49
        }
50
        //作为测试代理器
51 3
        $this->result['success'] = true;
52 3
        $this->result['info'] = "send voice verify to $to success [code = $code]";
53 3
    }
54
}
55