Completed
Push — master ( a3c7a7...bd72ff )
by Carlos
02:47
created

Base   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 55
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C getResponse() 0 25 8
1
<?php
2
/**
3
 * Base.php
4
 *
5
 * Part of Overtrue\Wechat\Shop\Foundation.
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @author    a939638621 <[email protected]>
11
 * @copyright 2015 a939638621 <[email protected]>
12
 * @link      https://github.com/a939638621
13
 */
14
15
namespace Overtrue\Wechat\Shop\Foundation;
16
17
18
use Overtrue\Wechat\Http;
19
20
class Base
21
{
22
    /**
23
     * @var Object Http
24
     */
25
    protected $http;
26
27
    /**
28
     * @var array|bool
29
     */
30
    protected $response;
31
32
    /**
33
     * 初始化
34
     *
35
     * @param Http $http
36
     */
37
    public function __construct(Http $http)
38
    {
39
        $this->http = $http;
40
    }
41
42
    /**
43
     * 获得响应
44
     *
45
     * @param array $response
46
     * @return bool|array
47
     * @throws ShopsException
48
     */
49
    protected function getResponse($response = array())
50
    {
51
        $response = empty($response) ? $this->response : $response ;
52
53
        if ($response['errcode'] == 0) {
54
55
            if (count($response) == 2)  return true;
56
            if (count($response) > 2) {
57
58
                if (isset($response['errmsg'])) unset($response['errmsg']);
59
                if (isset($response['errcode'])) unset($response['errcode']);
60
61
                if (count($response) == 1) {
62
                    $key = array_keys($response);
63
64
                    return $response[$key[0]];
65
                } else {
66
                    return $response;
67
                }
68
            }
69
70
        } else {
71
            throw new ShopsException($response['errmsg'],$response['errcode']);
72
        }
73
    }
74
}