Completed
Pull Request — master (#17)
by lan tian
03:35
created

ParasiticAgent::sendTemplateSms()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class ParasiticAgent
7
 * 寄生代理器
8
 *
9
 * @property string   $name
10
 * @property \Closure $sendSms
11
 * @property \Closure $voiceVerify
12
 */
13
class ParasiticAgent extends Agent
14
{
15
    protected $sendSmsRunning = false;
16
17
    protected $voiceVerifyRunning = false;
18
19 View Code Duplication
    public function sendSms($tempId, $to, array $tempData, $content)
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...
20
    {
21
        if (!is_callable($this->sendSms)) {
22
            $name = $this->name;
23
            throw new PhpSmsException("Please give parasitic agent [$name] a callable param named `sendSms` by enable config.");
24
        }
25
        if (!$this->sendSmsRunning) {
26
            $this->sendSmsRunning = true;
27
            try {
28
                call_user_func_array($this->sendSms, [$this, $tempId, $to, $tempData, $content]);
29
            } catch (\Exception $e) {
30
                $this->sendSmsRunning = false;
31
                throw $e;
32
            }
33
            $this->sendSmsRunning = false;
34
        } else {
35
            throw new PhpSmsException('Please do not use `$agent->sendSms()` in closure.');
36
        }
37
    }
38
39
    public function sendContentSms($to, $content)
40
    {
41
        throw new PhpSmsException('Parasitic agent does not support `sendContentSms` method.');
42
    }
43
44
    public function sendTemplateSms($tempId, $to, array $tempData)
45
    {
46
        throw new PhpSmsException('Parasitic agent does not support `sendTemplateSms` method.');
47
    }
48
49 View Code Duplication
    public function voiceVerify($to, $code)
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...
50
    {
51
        if (!is_callable($this->voiceVerify)) {
52
            $name = $this->name;
53
            throw new PhpSmsException("Please give parasitic agent [$name] a callable param named `voiceVerify` by enable config.");
54
        }
55
        if (!$this->voiceVerifyRunning) {
56
            $this->voiceVerifyRunning = true;
57
            try {
58
                call_user_func_array($this->voiceVerify, [$this, $to, $code]);
59
            } catch (\Exception $e) {
60
                $this->voiceVerifyRunning = false;
61
                throw $e;
62
            }
63
            $this->voiceVerifyRunning = false;
64
        } else {
65
            throw new PhpSmsException('Please do not use `$agent->voiceVerify()` in closure.');
66
        }
67
    }
68
}
69