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

Response   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromResponse() 0 9 1
A json() 0 4 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