Response   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 60
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getStatusCode() 0 4 1
A getTimestamp() 0 4 1
A getData() 0 4 1
A toJSON() 0 8 1
1
<?php
2
3
namespace Infinitypaul\NairaExchangeRates;
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
    /****************************/
32
    /*                          */
33
    /*         GETTERS          */
34
    /*                          */
35
    /****************************/
36
37
    // Get the status code:
38
    public function getStatusCode()
39
    {
40
        return (int) $this->statusCode;
41
    }
42
43
    //ÊGet the timestamp of the request:
44
    public function getTimestamp()
45
    {
46
        return $this->timestamp;
47
    }
48
49
    //ÊGet the timestamp of the request:
50
    public function getData()
51
    {
52
        return $this->body;
53
    }
54
55
    //ÊConvert the response to JSON:
56
    public function toJSON()
57
    {
58
        return json_encode([
59
            'statusCode'   => $this->getStatusCode(),
60
            'timestamp'    => $this->getTimestamp(),
61
            'body' => $this->getData(),
62
        ]);
63
    }
64
}
65