Result::setObservedValue()   A
last analyzed

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 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace Koality\ShopwarePlugin\Formatter;
4
5
/**
6
 * Class Result
7
 *
8
 * @package Koality\ShopwarePlugin\Formatter
9
 *
10
 * @author Nils Langner <[email protected]>
11
 * created 2020-12-23
12
 */
13
class Result
14
{
15
    const KEY_NEWSLETTER_TOO_FEW = 'newsletter.too_few';
16
    const KEY_ORDERS_TOO_FEW = 'orders.too_few';
17
    const KEY_CARTS_OPEN_TOO_MANY = 'carts.open.too_many';
18
    const KEY_PRODUCTS_ACTIVE = 'products.active';
19
    const KEY_PLUGINS_UPDATABLE = 'plugins.updatable';
20
21
    /** The allowed result statuses */
22
    const STATUS_PASS = 'pass';
23
    const STATUS_FAIL = 'fail';
24
25
    const LIMIT_TYPE_MIN = 'min';
26
    const LIMIT_TYPE_MAX = 'max';
27
28
    const TYPE_TIME_SERIES_NUMERIC = 'time_series_numeric';
29
    const TYPE_TIME_SERIES_PERCENT = 'time_series_percent';
30
31
    /**
32
     * @var string
33
     */
34
    private $status;
35
36
    /**
37
     * @var string
38
     */
39
    private $message;
40
41
    /**
42
     * @var string
43
     */
44
    private $key;
45
46
    /**
47
     * @var int
48
     */
49
    private $limit;
50
51
    /**
52
     * @var float|int
53
     */
54
    private $observedValue;
55
56
    /**
57
     * @var int
58
     */
59
    private $observedValuePrecision;
60
61
    /**
62
     * @var string
63
     */
64
    private $observedValueUnit;
65
66
    /**
67
     * @var string
68
     */
69
    private $limitType;
70
71
    /**
72
     * @var string
73
     */
74
    private $type;
75
76
    private $attributes = [];
77
78
    /**
79
     * Result constructor.
80
     *
81
     * @param string $status
82
     * @param string $key
83
     * @param string $message
84
     */
85
    public function __construct(string $status, string $key, string $message)
86
    {
87
        $this->status = $status;
88
        $this->message = $message;
89
        $this->key = $key;
90
    }
91
92
    /**
93
     * Return the results status. Can be fail or pass.
94
     *
95
     * Use the class constants for checking the status.
96
     *
97
     * @return string
98
     */
99
    public function getStatus()
100
    {
101
        return $this->status;
102
    }
103
104
    /**
105
     * Return the results message.
106
     *
107
     * @return string
108
     */
109
    public function getMessage()
110
    {
111
        return $this->message;
112
    }
113
114
    /**
115
     * Return the results unique key.
116
     *
117
     * @return string
118
     */
119
    public function getKey()
120
    {
121
        return $this->key;
122
    }
123
124
    /**
125
     * Get the limit of the metric that was checked.
126
     *
127
     * This field is optional.
128
     *
129
     * @return int|null
130
     */
131
    public function getLimit()
132
    {
133
        return $this->limit;
134
    }
135
136
    /**
137
     * Set the limit of the metric that was checked.
138
     *
139
     * @param int $limit
140
     */
141
    public function setLimit(int $limit)
142
    {
143
        $this->limit = $limit;
144
    }
145
146
    /**
147
     * Get the current value of the checked metric.
148
     *
149
     * This field is optional.
150
     *
151
     * @return mixed
152
     */
153
    public function getObservedValue()
154
    {
155
        return $this->observedValue;
156
    }
157
158
    /**
159
     * Set the current value if the metric that is checked.
160
     *
161
     * @param mixed $observedValue
162
     */
163
    public function setObservedValue($observedValue)
164
    {
165
        $this->observedValue = $observedValue;
166
    }
167
168
    /**
169
     * Return the unit of the observed value.
170
     *
171
     * @return string
172
     */
173
    public function getObservedValueUnit()
174
    {
175
        return $this->observedValueUnit;
176
    }
177
178
    /**
179
     * Set the unit of the observed value.
180
     *
181
     * @param string $observedValueUnit
182
     */
183
    public function setObservedValueUnit(string $observedValueUnit)
184
    {
185
        $this->observedValueUnit = $observedValueUnit;
186
    }
187
188
    /**
189
     * Add a new attribute to the result.
190
     *
191
     * @param string $key
192
     * @param mixed $value
193
     */
194
    public function addAttribute($key, $value)
195
    {
196
        $this->attributes[$key] = $value;
197
    }
198
199
    /**
200
     * Return a list of attribute
201
     *
202
     * @return array
203
     */
204
    public function getAttributes()
205
    {
206
        return $this->attributes;
207
    }
208
209
    /**
210
     * @return string
211
     */
212
    public function getLimitType()
213
    {
214
        return $this->limitType;
215
    }
216
217
    /**
218
     * @param string $limitType
219
     */
220
    public function setLimitType(string $limitType)
221
    {
222
        $this->limitType = $limitType;
223
    }
224
225
    /**
226
     * @return string
227
     */
228
    public function getType()
229
    {
230
        return $this->type;
231
    }
232
233
    /**
234
     * @param string $type
235
     */
236
    public function setType(string $type)
237
    {
238
        $this->type = $type;
239
    }
240
241
    /**
242
     * @return int
243
     */
244
    public function getObservedValuePrecision()
245
    {
246
        return $this->observedValuePrecision;
247
    }
248
249
    /**
250
     * @param int $observedValuePrecision
251
     */
252
    public function setObservedValuePrecision($observedValuePrecision)
253
    {
254
        $this->observedValuePrecision = $observedValuePrecision;
255
    }
256
}
257