Endpoint   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getResource() 0 6 1
A postResource() 0 6 1
A postResourceJson() 0 6 1
A postResourceFile() 0 6 1
A putResource() 0 6 1
A putResourceJson() 0 6 1
A deleteResource() 0 4 1
A getResourceUri() 0 6 2
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\EndPoints;
4
5
use seregazhuk\HeadHunterApi\Request;
6
7
abstract class Endpoint
8
{
9
    const RESOURCE = '/resource';
10
11
    /**
12
     * @var EndpointsContainer
13
     */
14
    protected $container;
15
16
    /**
17
     * @var Request
18
     */
19
    protected $request;
20
21
    /**
22
     * @param EndpointsContainer $container
23
     */
24
    public function __construct(EndpointsContainer $container)
25
    {
26
        $this->container = $container;
27
        $this->request = $this->container->getRequest();
28
    }
29
30
    /**
31
     * @param string $verb
32
     * @param array $params
33
     * @return array
34
     */
35
    protected function getResource($verb = '', array $params = [])
36
    {
37
        return $this->request->get(
38
            $this->getResourceUri($verb), $params
39
        );
40
    }
41
42
    /**
43
     * @param string $verb
44
     * @param array $params
45
     * @return mixed
46
     */
47
    protected function postResource($verb = '', array $params = [])
48
    {
49
        return $this->request->post(
50
            $this->getResourceUri($verb), $params
51
        );
52
    }
53
54
    /**
55
     * @param string $verb
56
     * @param array $params
57
     * @return mixed
58
     */
59
    protected function postResourceJson($verb = '', array $params = [])
60
    {
61
        return $this->request->postJson(
62
            $this->getResourceUri($verb), $params
63
        );
64
    }
65
66
    protected function postResourceFile($verb, array $params = [])
67
    {
68
        return $this->request->postFile(
69
            $this->getResourceUri($verb), $params
70
        );
71
    }
72
73
74
    /**
75
     * @param string $verb
76
     * @param array $params
77
     * @return mixed
78
     */
79
    protected function putResource($verb = '', array $params = [])
80
    {
81
        return $this->request->put(
82
            $this->getResourceUri($verb), $params
83
        );
84
    }
85
86
    /**
87
     * @param string $verb
88
     * @param array $params
89
     * @return mixed
90
     */
91
    protected function putResourceJson($verb = '', array $params = [])
92
    {
93
        return $this->request->putJson(
94
            $this->getResourceUri($verb), $params
95
        );
96
    }
97
98
    /**
99
     * @param string $verb
100
     * @param array $params
101
     * @return array|null
102
     */
103
    protected function deleteResource($verb = '', $params = [])
104
    {
105
        return $this->request->delete($this->getResourceUri($verb), $params);
106
    }
107
108
    /**
109
     * @param string $uri
110
     * @return string
111
     */
112
    protected function getResourceUri($uri = '')
113
    {
114
        $resource = static::RESOURCE;
115
116
        return empty($uri) ? $resource : $resource . sprintf('/%s', $uri);
117
    }
118
}