Test Failed
Branch master (7dbee5)
by Dmitry
15:35 queued 05:34
created

AbstractResult::getError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace TonicHealthCheck\Check;
4
5
use ZendDiagnostics\Result\ResultInterface;
6
7
/**
8
 * Class AbstractResult.
9
 */
10
abstract class AbstractResult implements ResultInterface
11
{
12
    const STATUS_OK = 0;
13
14
    /**
15
     * @var int
16
     */
17
    protected $status;
18
19
    /**
20
     * @var CheckException|null
21
     */
22
    protected $error;
23
24
    /**
25
     * CheckResult constructor.
26
     *
27
     * @param int            $status
28
     * @param CheckException $error
29
     */
30
    public function __construct($status, CheckException $error = null)
31
    {
32
        $this->setStatus($status);
33
        $this->setError($error);
34
    }
35
36
    /**
37
     * @return int
38
     */
39
    public function getStatus()
40
    {
41
        return $this->status;
42
    }
43
44
    /**
45
     * @return CheckException|null
46
     */
47
    public function getError()
48
    {
49
        return $this->error;
50
    }
51
52
    /**
53
     * @return bool
54
     */
55
    public function isOk()
56
    {
57
        return $this->getStatus() == static::STATUS_OK;
58
    }
59
60
    /**
61
     * Get message related to the result.
62
     *
63
     * @return string
64
     */
65
    public function getMessage()
66
    {
67
        if ($this->isOk()) {
68
            return '';
69
        }
70
71
        return $this->getError()->getMessage();
72
    }
73
74
    /**
75
     * Get detailed info on the test result (if available).
76
     *
77
     * @return mixed|null
78
     */
79
    public function getData()
80
    {
81
        $this->getStatus();
0 ignored issues
show
Unused Code introduced by
The call to the method TonicHealthCheck\Check\AbstractResult::getStatus() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
82
    }
83
84
    /**
85
     * @param int $status
86
     */
87
    protected function setStatus($status)
88
    {
89
        $this->status = $status;
90
    }
91
92
    /**
93
     * @param CheckException|null $error
94
     */
95
    protected function setError(CheckException $error = null)
96
    {
97
        $this->error = $error;
98
    }
99
}
100