Passed
Push — master ( 93501e...841558 )
by Dmitry
10:30
created

CheckResult::errorResult()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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