Request   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 16
c 1
b 0
f 0
dl 0
loc 81
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 3 1
A getAppId() 0 3 1
A __call() 0 8 2
A __set() 0 4 1
A getAppKey() 0 3 1
1
<?php
2
3
4
namespace MuCTS\Sobot\Contracts;
5
6
7
abstract class Request
8
{
9
    protected $config = [];
10
    protected $cache;
11
    protected $param = [];
12
13
    public function __construct(array $config, ?Cache $cache = null)
14
    {
15
        $this->config = $config;
16
        $this->cache = $cache;
17
    }
18
19
    /**
20
     * 获取应用ID
21
     *
22
     * @return string
23
     * @author herry.yao <[email protected]>
24
     * @version 1.2.2
25
     * @date 2020-08-05
26
     */
27
    public function getAppId(): string
28
    {
29
        return $this->config['app_id'];
30
    }
31
32
    /**
33
     * 获取授权秘钥
34
     *
35
     * @return string
36
     * @author herry.yao <[email protected]>
37
     * @version 1.2.2
38
     * @date 2020-08-05
39
     */
40
    protected function getAppKey(): string
41
    {
42
        return $this->config['app_key'];
43
    }
44
45
    /**
46
     * 返回数组
47
     *
48
     * @return array
49
     * @author herry.yao <[email protected]>
50
     * @version 1.2.2
51
     * @date 2020-08-05
52
     */
53
    public function toArray(): array
54
    {
55
        return $this->param;
56
    }
57
58
    /**
59
     * call
60
     *
61
     * @param $name
62
     * @param $arguments
63
     * @return Request
64
     * @version 1.2.2
65
     * @date 2020-08-05
66
     * @author herry.yao <[email protected]>
67
     */
68
    public function __call($name, $arguments)
69
    {
70
        $name = hump_to_underline($name);
71
        if (strpos($name, 'where') === 0) {
72
            $name = substr($name, 6);
73
        }
74
        $this->param[$name] = $arguments[0];
75
        return $this;
76
    }
77
78
    /**
79
     * 魔术方法赋值
80
     *
81
     * @param $name
82
     * @param $value
83
     */
84
    public function __set($name, $value)
85
    {
86
        $name = hump_to_underline($name);
87
        $this->param[$name] = $value;
88
    }
89
}