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
|
|
|
const KOALITY_IDENTIFIER_ORDERS_TOO_FEW = 'orders.too_few'; |
32
|
|
|
const KOALITY_IDENTIFIER_PLUGINS_UPDATABLE = 'plugins.updatable'; |
33
|
|
|
const KOALITY_IDENTIFIER_PRODUCTS_COUNT = 'products.active'; |
34
|
|
|
|
35
|
|
|
const KOALITY_IDENTIFIER_SYSTEM_INSECURE = 'system.insecure'; |
36
|
|
|
const KOALITY_IDENTIFIER_SECURITY_USERS_ADMIN_COUNT = 'security.user.admin.count'; |
37
|
|
|
|
38
|
|
|
const KOALITY_IDENTIFIER_SERVER_DICS_SPACE_USED = 'server.space.used'; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
*/ |
43
|
|
|
private $status; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @var string |
47
|
|
|
*/ |
48
|
|
|
private $message; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @var array |
52
|
|
|
*/ |
53
|
|
|
private $attributes = []; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Result constructor. |
57
|
|
|
* |
58
|
|
|
* @param $status |
59
|
|
|
* @param $message |
60
|
|
|
*/ |
61
|
|
|
public function __construct($status, $message = "") |
62
|
|
|
{ |
63
|
|
|
$this->status = $status; |
64
|
|
|
$this->message = $message; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @return string |
69
|
|
|
*/ |
70
|
|
|
public function getStatus() |
71
|
|
|
{ |
72
|
|
|
return $this->status; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
|
|
public function getMessage() |
79
|
|
|
{ |
80
|
|
|
return $this->message; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Add a new attribute to the result. |
85
|
|
|
* |
86
|
|
|
* @param string $key |
87
|
|
|
* @param mixed $value |
88
|
|
|
*/ |
89
|
|
|
public function addAttribute($key, $value) |
90
|
|
|
{ |
91
|
|
|
$this->attributes[$key] = $value; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* Return a list of attribute |
96
|
|
|
* |
97
|
|
|
* @return array |
98
|
|
|
*/ |
99
|
|
|
public function getAttributes() |
100
|
|
|
{ |
101
|
|
|
return $this->attributes; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the higher weighted status. |
106
|
|
|
* |
107
|
|
|
* @param $status1 |
108
|
|
|
* @param $status2 |
109
|
|
|
* |
110
|
|
|
* @return string |
111
|
|
|
*/ |
112
|
|
|
public static function getHigherWeightedStatus($status1, $status2) |
113
|
|
|
{ |
114
|
|
|
if (self::$statuses[$status1] > self::$statuses[$status2]) { |
115
|
|
|
return $status1; |
116
|
|
|
} else { |
117
|
|
|
return $status2; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|