ParasiticAgent   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 2
cbo 1
dl 0
loc 113
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A sendContentSms() 0 4 1
A sendContentVoice() 0 4 1
A sendFileVoice() 0 4 1
A sendTemplateSms() 0 4 1
A sendTemplateVoice() 0 4 1
A sendVoiceCode() 0 4 1
A handle() 0 7 3
A methods() 0 12 3
1
<?php
2
3
namespace Toplan\PhpSms;
4
5
/**
6
 * Class ParasiticAgent
7
 * 寄生代理器
8
 */
9
class ParasiticAgent extends Agent implements ContentSms, TemplateSms, VoiceCode, ContentVoice, TemplateVoice, FileVoice
10
{
11
    protected static $methods;
12
13
    protected $handlers = [];
14
15
    public function __construct(array $config = [], array $handlers = [])
16
    {
17
        parent::__construct($config);
18
19
        $this->handlers = $handlers;
20
    }
21
22
    /**
23
     * Content SMS send process.
24
     *
25
     * @param string|array $to
26
     * @param string       $content
27
     */
28
    public function sendContentSms($to, $content)
29
    {
30
        $this->handle(__FUNCTION__, func_get_args());
31
    }
32
33
    /**
34
     * Content voice send process.
35
     *
36
     * @param string|array $to
37
     * @param string       $content
38
     */
39
    public function sendContentVoice($to, $content)
40
    {
41
        $this->handle(__FUNCTION__, func_get_args());
42
    }
43
44
    /**
45
     * File voice send process.
46
     *
47
     * @param string|array $to
48
     * @param int|string   $fileId
49
     */
50
    public function sendFileVoice($to, $fileId)
51
    {
52
        $this->handle(__FUNCTION__, func_get_args());
53
    }
54
55
    /**
56
     * Template SMS send process.
57
     *
58
     * @param string|array $to
59
     * @param int|string   $tempId
60
     * @param array        $tempData
61
     */
62
    public function sendTemplateSms($to, $tempId, array $tempData)
63
    {
64
        $this->handle(__FUNCTION__, func_get_args());
65
    }
66
67
    /**
68
     * Template voice send process.
69
     *
70
     * @param string|array $to
71
     * @param int|string   $tempId
72
     * @param array        $tempData
73
     */
74
    public function sendTemplateVoice($to, $tempId, array $tempData)
75
    {
76
        $this->handle(__FUNCTION__, func_get_args());
77
    }
78
79
    /**
80
     * Voice code send process.
81
     *
82
     * @param string|array $to
83
     * @param int|string   $code
84
     */
85
    public function sendVoiceCode($to, $code)
86
    {
87
        $this->handle(__FUNCTION__, func_get_args());
88
    }
89
90
    /**
91
     * Handle send process by closure.
92
     *
93
     * @param       $name
94
     * @param array $args
95
     */
96
    protected function handle($name, array $args = [])
97
    {
98
        if (isset($this->handlers[$name]) && is_callable($this->handlers[$name])) {
99
            array_unshift($args, $this);
100
            call_user_func_array($this->handlers[$name], $args);
101
        }
102
    }
103
104
    /**
105
     * Get methods name which inherit from interfaces.
106
     *
107
     * @return array
108
     */
109
    public static function methods()
110
    {
111
        if (!is_array(self::$methods)) {
112
            self::$methods = [];
113
            $interfaces = class_implements('Toplan\\PhpSms\\ParasiticAgent');
114
            foreach ($interfaces as $interface) {
115
                self::$methods = array_merge(self::$methods, get_class_methods($interface));
116
            }
117
        }
118
119
        return self::$methods;
120
    }
121
}
122