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

ParasiticAgent   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 44
Duplicated Lines 81.82 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 2
cbo 2
dl 36
loc 44
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendSms() 18 18 4
A voiceVerify() 18 18 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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