Passed
Push — master ( f283f5...2c6f24 )
by Nils
04:41
created

Result::addAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Leankoala\HealthFoundation\Check;
4
5
class Result
6
{
7
    /**
8
     * Healthy
9
     */
10
    const STATUS_PASS = 'pass';
11
12
    /**
13
     * Healthy, with some concerns
14
     */
15
    const STATUS_WARN = 'warn';
16
17
    /**
18
     * Unhealthy
19
     */
20
    const STATUS_FAIL = 'fail';
21
22
    private static $statuses = [
23
        self::STATUS_PASS => 0,
24
        self::STATUS_WARN => 50,
25
        self::STATUS_FAIL => 100
26
    ];
27
28
    const LIMIT_TYPE_MIN = 'min';
29
    const LIMIT_TYPE_MAX = 'max';
30
31
    /**
32
     * @var string
33
     */
34
    private $status;
35
36
    /**
37
     * @var string
38
     */
39
    private $message;
40
41
    /**
42
     * @var array
43
     */
44
    private $attributes = [];
45
46
    /**
47
     * Result constructor.
48
     *
49
     * @param $status
50
     * @param $message
51
     */
52
    public function __construct($status, $message = "")
53
    {
54
        $this->status = $status;
55
        $this->message = $message;
56
    }
57
58
    /**
59
     * @return string
60
     */
61
    public function getStatus()
62
    {
63
        return $this->status;
64
    }
65
66
    /**
67
     * @return string
68
     */
69
    public function getMessage()
70
    {
71
        return $this->message;
72
    }
73
74
    /**
75
     * Add a new attribute to the result.
76
     *
77
     * @param string $key
78
     * @param mixed $value
79
     */
80
    public function addAttribute($key, $value)
81
    {
82
        $this->attributes[$key] = $value;
83
    }
84
85
    /**
86
     * Return a list of attribute
87
     *
88
     * @return array
89
     */
90
    public function getAttributes()
91
    {
92
        return $this->attributes;
93
    }
94
95
    /**
96
     * Returns the higher weighted status.
97
     *
98
     * @param $status1
99
     * @param $status2
100
     *
101
     * @return string
102
     */
103
    public static function getHigherWeightedStatus($status1, $status2)
104
    {
105
        if (self::$statuses[$status1] > self::$statuses[$status2]) {
106
            return $status1;
107
        } else {
108
            return $status2;
109
        }
110
    }
111
}
112