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

CheckResult   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 8
c 3
b 1
f 1
lcom 1
cbo 0
dl 0
loc 85
ccs 20
cts 20
cp 1
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A okResult() 0 4 1
A errorResult() 0 4 1
A getStatus() 0 4 1
A getError() 0 4 1
A isOk() 0 4 1
A setStatus() 0 4 1
A setError() 0 4 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