Completed
Push — master ( 4ed813...32abb8 )
by Sergey
04:41 queued 02:10
created

GuzzleHttpAdapter::parseResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\SmsIntel\Adapters;
4
5
use Guzzle\Http\Client;
6
use Guzzle\Http\Message\Response;
7
use seregazhuk\SmsIntel\Contracts\HttpInterface;
8
9
class GuzzleHttpAdapter implements HttpInterface {
10
11
    /**
12
     * @var Client
13
     */
14
    protected $client;
15
16
    public function __construct()
17
    {
18
        $this->client = new Client();
19
    }
20
	
21
    /**
22
     * @param $uri
23
     * @param array $params
24
     * @return array
25
     */
26
    public function get($uri, $params = [])
27
    {
28
        if(!empty($params)){
29
            $uri .= '?'. http_build_query($params);
30
        }
31
        $response = $this
32
            ->client
33
            ->get($uri)
34
            ->send();
35
36
        return $this->parseResponse($response);
0 ignored issues
show
Bug introduced by
The method parseResponse() does not seem to exist on object<seregazhuk\SmsInt...ters\GuzzleHttpAdapter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
    }
38
39
    /**
40
     * @param string $uri
41
     * @param array $body
42
     * @return array
43
     */
44
    public function post($uri, $body)
45
    {
46
        return $this
47
            ->client
48
            ->post($uri, [], $body)
49
            ->send()
50
            ->getBody(true);
51
    }
52
53
    /**
54
     * @param string $url
55
     * @return $this
56
     */
57
    public function setBaseUrl($url)
58
    {
59
        $this->client->setBaseUrl($url);
60
61
        return $this;
62
    }
63
}