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

ParasiticAgent::sendTemplateSms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class ParasiticAgent
7
 * 寄生代理器
8
 *
9
 * @property \Closure $sendSms
10
 * @property \Closure $voiceVerify
11
 */
12
class ParasiticAgent extends Agent
13
{
14
    protected $sendSmsRunning = false;
15
16
    protected $voiceVerifyRunning = false;
17
18 View Code Duplication
    public function sendSms($to, $content, $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...
19
    {
20
        if (!is_callable($this->sendSms)) {
21
            throw new PhpSmsException('Expected the higher-order scheme option `sendSms` to be a closure.');
22
        }
23
        if ($this->sendSmsRunning) {
24
            throw new PhpSmsException('Do not call `$agent->sendSms()` in the closure.');
25
        }
26
        $this->sendSmsRunning = true;
27
        try {
28
            call_user_func_array($this->sendSms, [$this, $to, $content, $tempId, $data]);
29
            $this->sendSmsRunning = false;
30
        } catch (\Exception $e) {
31
            $this->sendSmsRunning = false;
32
33
            throw $e;
34
        }
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
        if (!is_callable($this->voiceVerify)) {
40
            throw new PhpSmsException('Expected the higher-order scheme option `voiceVerify` to be a closure.');
41
        }
42
        if ($this->voiceVerifyRunning) {
43
            throw new PhpSmsException('Do not call `$agent->voiceVerify()` in the closure.');
44
        }
45
        $this->voiceVerifyRunning = true;
46
        try {
47
            call_user_func_array($this->voiceVerify, [$this, $to, $code, $tempId, $data]);
48
            $this->voiceVerifyRunning = false;
49
        } catch (\Exception $e) {
50
            $this->voiceVerifyRunning = false;
51
52
            throw $e;
53
        }
54
    }
55
}
56