Response::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Parkwayprojects\PayWithBank3D\Controllers;
4
5
class Response
6
{
7
    // The actual Guzzle response:
8
    private $response;
9
10
    // Core response:
11
    private $headers;
12
    private $bodyRaw;
13
    private $body;
14
15
    // Properties:
16
    private $statusCode;
17
    private $timestamp;
18
19
    public function __construct(\GuzzleHttp\Psr7\Response $response)
20
    {
21
        $this->response = $response;
22
        $this->headers = $response->getHeaders();
23
        $this->bodyRaw = (string) $response->getBody();
24
        $this->body = json_decode($this->bodyRaw);
25
26
        // Set our properties:
27
        $this->statusCode = $response->getStatusCode();
28
        $this->timestamp = date('c');
29
    }
30
31
    public function getStatusCode()
32
    {
33
        return (int) $this->statusCode;
34
    }
35
36
    public function getTimestamp()
37
    {
38
        return $this->timestamp;
39
    }
40
41
    public function getData()
42
    {
43
        return $this->body;
44
    }
45
46
    public function getHeader()
47
    {
48
        return $this->headers;
49
    }
50
51
    public function toJSON()
52
    {
53
        return json_encode([
54
            'statusCode'   => $this->getStatusCode(),
55
            'timestamp'    => $this->getTimestamp(),
56
            'body' => $this->getData(),
57
        ], true);
58
    }
59
}
60