Response::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the LetsEncrypt ACME client.
7
 *
8
 * @author    Ivanov Aleksandr <[email protected]>
9
 * @copyright 2019-2020
10
 * @license   https://github.com/misantron/letsencrypt-client/blob/master/LICENSE MIT License
11
 */
12
13
namespace LetsEncrypt\Http;
14
15
use Psr\Http\Message\ResponseInterface;
16
17
final class Response
18
{
19
    private const HEADER_LOCATION = 'Location';
20
21
    /**
22
     * @var ResponseInterface
23
     */
24
    private $origin;
25
26
    public function __construct(ResponseInterface $origin)
27
    {
28
        $this->origin = $origin;
29
    }
30
31
    /**
32
     * Check if response return 200 status code.
33
     */
34
    public function isStatusOk(): bool
35
    {
36
        return $this->origin->getStatusCode() === 200;
37
    }
38
39
    public function getDecodedContent(): array
40
    {
41
        $body = $this->origin->getBody();
42
        // rewind stream before read response content
43
        $body->rewind();
44
45
        return json_decode($body->getContents(), true);
46
    }
47
48
    public function getRawContent(): string
49
    {
50
        return $this->origin->getBody()->getContents();
51
    }
52
53
    public function getLocation(): string
54
    {
55
        return $this->origin->getHeaderLine(self::HEADER_LOCATION);
56
    }
57
}
58