BaseIMCloud   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
dl 0
loc 76
ccs 4
cts 18
cp 0.2222
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A initialize() 0 3 1
A httpPost() 0 6 1
A httpPostJson() 0 6 2
A request() 0 13 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: lenovo
5
 * Date: 6/14/2018
6
 * Time: 1:56 PM
7
 */
8
9
namespace TimSDK\Core;
10
11
use TimSDK\Support\Json;
12
use TimSDK\Foundation\ResponseBag;
13
use TimSDK\Container\ServiceContainer;
14
use Psr\Http\Message\ResponseInterface;
15
16
class BaseIMCloud
17
{
18
    /**
19
     * @var ServiceContainer
20
     */
21
    protected $app;
22
23
    /**
24
     * AbstractTimSDKAPI constructor.
25
     * @param ServiceContainer $app
26
     */
27 6
    public function __construct(ServiceContainer $app)
28
    {
29 6
        $this->app = $app;
30
31 6
        $this->initialize();
32 2
    }
33
34
    /**
35
     * Init
36
     */
37
    public function initialize()
38
    {
39
    }
40
41
    /**
42
     * POST request.
43
     *
44
     * @param       $uri
45
     * @param array $data
46
     * @param array $options
47
     * @return ResponseBag
48
     */
49
    public function httpPost($uri, $data = [], $options = [])
50
    {
51
        return $this->request($uri, 'POST', array_merge($options, [
52
            'form_params' => $data
53
        ]));
54
    }
55
56
    /**
57
     * JSON request.
58
     *
59
     * @param       $uri
60
     * @param array $data
61
     * @param array $options
62
     * @return ResponseBag
63
     * @throws Exceptions\JsonParseException
64
     */
65
    public function httpPostJson($uri, $data = [], $options = [])
66
    {
67
        return $this->request($uri, 'POST', array_merge($options, [
68
            'body' => is_array($data) ? Json::encode($data) : $data
69
        ]));
70
    }
71
72
    /**
73
     * @param string $method
74
     * @param string $uri
75
     * @param array  $options
76
     * @return ResponseBag
77
     */
78
    public function request($uri, $method = 'GET', $options = [])
79
    {
80
        /**
81
         * @var ResponseInterface $response
82
         */
83
        $response = $this->app->httpClient->request($method, $uri, $options);
84
85
        return new ResponseBag(
86
            $response->getBody()->getContents(),
87
            $response->getHeaders(),
88
            $response->getStatusCode()
89
        );
90
    }
91
}
92