Passed
Pull Request — master (#24)
by
unknown
03:26
created

Guzzle6ApiClient::serializeResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.4285
c 0
b 0
f 0
nc 1
cc 1
eloc 7
nop 1
1
<?php
2
3
namespace MovingImage\Client\VMPro\ApiClient;
4
5
use MovingImage\Client\VMPro\Interfaces\ApiClientInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use GuzzleHttp\Psr7\Response;
8
9
/**
10
 * Class Guzzle6ApiClient.
11
 *
12
 * @author Ruben Knol <[email protected]>
13
 */
14
class Guzzle6ApiClient extends AbstractApiClient implements ApiClientInterface
15
{
16
    /**
17
     * Guzzle6 Client implementation for making HTTP requests with
18
     * the appropriate options.
19
     *
20
     * @param string $method
21
     * @param string $uri
22
     * @param array  $options
23
     *
24
     * @return mixed
25
     */
26
    protected function _doRequest($method, $uri, $options)
27
    {
28
        return $this->httpClient->request($method, $uri, $options);
29
    }
30
31
    /**
32
     * @inheritdoc
33
     * @param ResponseInterface $response
34
     * @return string
35
     */
36 View Code Duplication
    protected function serializeResponse($response)
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...
37
    {
38
        /** @var ResponseInterface $response */
39
        $serialized = serialize([
40
            $response->getStatusCode(),
41
            $response->getHeaders(),
42
            $response->getBody()->getContents(),
43
        ]);
44
45
        //subsequent calls need to access the stream from the beginning
46
        $response->getBody()->rewind();
47
48
        return $serialized;
49
    }
50
51
    /**
52
     * @inheritdoc
53
     * @param string $serialized
54
     * @return ResponseInterface
55
     * @throws Exception
56
     */
57
    protected function unserializeResponse($serialized)
58
    {
59
        $array = unserialize($serialized);
60
        if (!is_array($array) || count($array) !== 3) {
61
            throw new Exception(sprintf('Error unserializing response: %s', $serialized));
62
63
        }
64
65
        return new Response($array[0], $array[1], $array[2]);
66
    }
67
}
68