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

LogAgent   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 83.33%

Importance

Changes 6
Bugs 2 Features 1
Metric Value
wmc 7
c 6
b 2
f 1
lcom 1
cbo 1
dl 0
loc 43
ccs 20
cts 24
cp 0.8333
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A sendSms() 0 15 3
A sendContentSms() 0 5 1
A sendTemplateSms() 0 5 1
A voiceVerify() 0 12 2
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