Completed
Push — master ( 5d7f79...9c70e0 )
by Sergey
02:25
created

Request   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 61
rs 10
c 2
b 1
f 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A get() 0 6 1
A post() 0 6 1
A delete() 0 6 1
A createHeaders() 0 8 2
1
<?php
2
3
namespace seregazhuk\HeadHunterApi;
4
5
6
use seregazhuk\HeadHunterApi\Contracts\HttpInterface;
7
use seregazhuk\HeadHunterApi\Contracts\RequestInterface;
8
9
class Request implements RequestInterface
10
{
11
    /**
12
     * @var HttpInterface
13
     */
14
    protected $client;
15
16
    /**
17
     * @var null|string
18
     */
19
    protected $token;
20
21
    public function __construct(HttpInterface $http, $token = null)
22
    {
23
        $this->client = $http;
24
        $this->token = $token;
25
    }
26
27
    /**
28
     * @param string $uri
29
     * @param array $params
30
     * @return array|null
31
     */
32
    public function get($uri, $params = [])
33
    {
34
        $headers = $this->createHeaders();
35
36
        return $this->client->get($uri, $params, $headers);
37
    }
38
39
    /**
40
     * @param string $uri
41
     * @param array $params
42
     * @return array
43
     */
44
    public function post($uri, $params = [])
45
    {
46
        $headers = $this->createHeaders();
47
48
        return $this->client->post($uri, $params, $headers);
49
    }
50
51
    public function delete($uri)
52
    {
53
        $headers = $this->createHeaders();
54
55
        return $this->client->delete($uri, $headers);
56
    }
57
58
    /**
59
     * @return array|null
60
     */
61
    protected function createHeaders()
62
    {
63
        $headers = null;
64
65
        if(isset($this->token)) $headers['Authorization'] = 'Bearer ' . $this->token;
66
67
        return $headers;
68
    }
69
}