BaseHandler   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 101
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
send() 0 1 ?
A __construct() 0 7 1
A handle() 0 8 1
A setApiUrl() 0 4 1
A setInputKey() 0 4 1
A getEndpoint() 0 4 1
A parseResponse() 0 4 1
1
<?php namespace Understand\UnderstandLaravel5\Handlers;
2
3
abstract class BaseHandler
4
{
5
6
    /**
7
     * Input token
8
     *
9
     * @var string
10
     */
11
    protected $inputToken;
12
13
    /**
14
     * API url
15
     *
16
     * @var string
17
     */
18
    protected $apiUrl;
19
20
    /**
21
     * SSL CA bundle path
22
     *
23
     * @var string
24
     */
25
    protected $sslBundlePath;
26
27
    /**
28
     * Send data to storage
29
     *
30
     * @param string $data
31
     * @return string
32
     */
33
    abstract protected function send($data);
34
35
    /**
36
     * @param string $inputToken
37
     * @param string $apiUrl
38
     * @param string $sslBundlePath
39
     */
40
    public function __construct($inputToken, $apiUrl, $sslBundlePath = null)
41
    {
42
        $this->setInputKey($inputToken);
43
        $this->setApiUrl($apiUrl);
44
45
        $this->sslBundlePath = $sslBundlePath;
46
    }
47
48
    /**
49
     * Serialize data and send to storage
50
     *
51
     * @param array $requestData
52
     * @return array
53
     */
54
    public function handle(array $requestData)
55
    {
56
        $json = json_encode($requestData);
57
58
        $response = $this->send($json);
59
60
        return $this->parseResponse($response);
61
    }
62
63
    /**
64
     * Set api url
65
     *
66
     * @param string $apiUrl
67
     */
68
    protected function setApiUrl($apiUrl)
69
    {
70
        $this->apiUrl = $apiUrl;
71
    }
72
73
    /**
74
     * Set input key
75
     *
76
     * @param string $inputToken
77
     */
78
    protected function setInputKey($inputToken)
79
    {
80
        $this->inputToken = $inputToken;
81
    }
82
83
    /**
84
     * Return endpoint
85
     *
86
     * @return string
87
     */
88
    protected function getEndpoint()
89
    {
90
        return implode('/', [$this->apiUrl, $this->inputToken]);
91
    }
92
93
    /**
94
     * Parse respnse into array
95
     *
96
     * @param string $response
97
     * @return array
98
     */
99
    protected function parseResponse($response)
100
    {
101
        return json_decode($response, true);
102
    }
103
}
104