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

GuzzleHttpAdater::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 2
1
<?php
2
3
namespace seregazhuk\HeadHunterApi\Adapters;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Psr7\Request;
7
use GuzzleHttp\Psr7\Response;
8
use seregazhuk\HeadHunterApi\Contracts\HttpInterface;
9
10
class GuzzleHttpAdater implements HttpInterface
11
{
12
    /**
13
     * @var Client
14
     */
15
    protected $client;
16
17
    public function __construct($baseUrl)
18
    {
19
        $this->client = new Client(['base_uri' => $baseUrl]);
20
    }
21
22
    /**
23
     * @param string $uri
24
     * @param array $params
25
     * @param null $headers
26
     * @return array|null
27
     */
28
    public function get($uri, $params = [], $headers = null)
29
    {
30
        if(!empty($params)){
31
            $uri .= '?'. http_build_query($params);
32
        }
33
34
        $request = new Request('GET', $uri, $headers);
0 ignored issues
show
Documentation introduced by
$headers is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
35
36
        $response = $this
37
            ->client
38
            ->send($request);
39
40
        return $this->parseResponse($response);
0 ignored issues
show
Compatibility introduced by
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
41
    }
42
43
    /**
44
     * @param string $uri
45
     * @param array $params
46
     * @param null $headers
47
     * @return array|null
48
     */
49 View Code Duplication
    public function post($uri, $params = [], $headers = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
50
    {
51
        $request = new Request('POST', $uri, $headers);
0 ignored issues
show
Documentation introduced by
$headers is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52
53
        $response = $this
54
            ->client
55
            ->send($request, ['query' => $params]);
56
57
        return $this->parseResponse($response);
0 ignored issues
show
Compatibility introduced by
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
58
    }
59
60
    /**
61
     * @param string $uri
62
     * @param null $headers
63
     * @return array|null
64
     */
65 View Code Duplication
    public function delete($uri, $headers = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
    {
67
        $request = new Request('DELETE', $uri, $headers);
0 ignored issues
show
Documentation introduced by
$headers is of type null, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
68
69
        $response = $this
70
            ->client
71
            ->send($request);
72
73
        return $this->parseResponse($response);
0 ignored issues
show
Compatibility introduced by
$response of type object<Psr\Http\Message\ResponseInterface> is not a sub-type of object<GuzzleHttp\Psr7\Response>. It seems like you assume a concrete implementation of the interface Psr\Http\Message\ResponseInterface to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
74
    }
75
76
    /**
77
     * @param Response $response
78
     * @return array|null
79
     */
80
    private function parseResponse(Response $response)
81
    {
82
        return json_decode($response->getBody(), true);
83
    }
84
85
}