AbstractResult   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 0
dl 0
loc 88
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

8 Methods

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