AbstractResult::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace TonicHealthCheck\Check;
4
5
/**
6
 * Class AbstractResult.
7
 */
8
abstract class AbstractResult implements ResultInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $status;
14
15
    /**
16
     * @var CheckException|null
17
     */
18
    protected $error;
19
20
    /**
21
     * CheckResult constructor.
22
     *
23
     * @param int            $status
24
     * @param CheckException $error
25
     */
26 4
    public function __construct($status, CheckException $error = null)
27
    {
28 4
        $this->setStatus($status);
29 4
        $this->setError($error);
30 4
    }
31
32
    /**
33
     * @return int
34
     */
35 4
    public function getStatus()
36
    {
37 4
        return $this->status;
38
    }
39
40
    /**
41
     * @return CheckException|null
42
     */
43 4
    public function getError()
44
    {
45 4
        return $this->error;
46
    }
47
48
    /**
49
     * @return bool
50
     */
51 4
    public function isOk()
52
    {
53 4
        return $this->getStatus() == static::STATUS_OK;
54
    }
55
56
    /**
57
     * Get message related to the result.
58
     *
59
     * @return string
60
     */
61 2
    public function getMessage()
62
    {
63 2
        if ($this->isOk()) {
64 1
            return '';
65
        }
66
67 1
        return $this->getError()->getMessage();
68
    }
69
70
    /**
71
     * Get detailed info on the test result (if available).
72
     *
73
     * @return mixed|null
74
     */
75 2
    public function getData()
76
    {
77 2
        return $this->getStatus();
78
    }
79
80
    /**
81
     * @param int $status
82
     */
83 4
    protected function setStatus($status)
84
    {
85 4
        $this->status = $status;
86 4
    }
87
88
    /**
89
     * @param CheckException|null $error
90
     */
91 4
    protected function setError(CheckException $error = null)
92
    {
93 4
        $this->error = $error;
94 4
    }
95
}
96