Completed
Push — master ( 83b55d...472d84 )
by Justin
03:47 queued 36s
created

Response::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php namespace Rollbar;
2
3
class Response
4
{
5
    private $status;
6
    private $info;
7
    private $uuid;
8
9
    public function __construct($status, $info, $uuid = null)
10
    {
11
        $this->status = $status;
12
        $this->info = $info;
13
        $this->uuid = $uuid;
14
    }
15
16
    public function getStatus()
17
    {
18
        return $this->status;
19
    }
20
21
    public function getInfo()
22
    {
23
        return $this->info;
24
    }
25
26
    public function getUuid()
27
    {
28
        return $this->uuid;
29
    }
30
31
    public function wasSuccessful()
32
    {
33
        return $this->status >= 200 && $this->status < 300;
34
    }
35
36
    public function getOccurrenceUrl()
37
    {
38
        if (is_null($this->uuid)) {
39
            return null;
40
        }
41
        if (!$this->wasSuccessful()) {
42
            return null;
43
        }
44
        return "https://rollbar.com/occurrence/uuid/?uuid=" . $this->uuid;
45
    }
46
47
    public function __toString()
48
    {
49
        $url = $this->getOccurrenceUrl();
50
        return "Status: $this->status\n" .
51
               "Body: " . json_encode($this->info) . "\n" .
52
               "URL: $url";
53
    }
54
}
55