Completed
Pull Request — master (#5)
by Marin
01:10
created

Response::fromResponse()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 1
1
<?php
2
3
namespace Anorgan\Onfleet;
4
5
use GuzzleHttp\Psr7\Response as BaseResponse;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Class Response
10
 * @package Anorgan\Onfleet
11
 */
12
class Response extends BaseResponse
13
{
14
    /**
15
     * @param ResponseInterface $response
16
     * @return Response
17
     */
18
    public static function fromResponse(ResponseInterface $response): Response
19
    {
20
        return new static(
21
            $response->getStatusCode(),
22
            $response->getHeaders(),
23
            $response->getBody(),
24
            $response->getProtocolVersion(),
25
            $response->getReasonPhrase());
26
    }
27
28
    /**
29
     * @param bool $array
30
     * @return array|null|object
31
     */
32
    public function json(bool $array = false)
33
    {
34
        return json_decode($this->getBody(), $array);
35
    }
36
}
37