Completed
Push — master ( b4c156...d0dba3 )
by Sergey
02:38
created

Request::createHeaders()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
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
    const BASE_URL = 'https://api.hh.ru';
12
    private $client;
13
    private $token;
14
15
    public function __construct(HttpInterface $http, $token = null)
16
    {
17
        $http->setBaseUrl(self::BASE_URL);
18
        $this->client = $http;
19
        $this->token = $token;
20
    }
21
22
    public function get($uri, $params = [])
23
    {
24
        $headers = $this->createHeaders();
25
        return $this->client->get($uri, $params, $headers);
0 ignored issues
show
Bug introduced by
It seems like $headers defined by $this->createHeaders() on line 24 can also be of type array; however, seregazhuk\HeadHunterApi...ts\HttpInterface::get() does only seem to accept null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
26
    }
27
28
    /**
29
     * @return array|null
30
     */
31
    protected function createHeaders()
32
    {
33
        $headers = null;
34
        if(isset($this->token)) $headers['Authorization'] = 'Bearer ' . $this->token;
35
36
        return $headers;
37
    }
38
}