Total Complexity | 5 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
8 | class ApiHealthChecker |
||
9 | { |
||
10 | /** |
||
11 | * Boolean wether to use the state storage. |
||
12 | * |
||
13 | * @var bool |
||
14 | */ |
||
15 | private $useStateStorage = true; |
||
16 | |||
17 | /** |
||
18 | * Disables the use of the state storage. |
||
19 | * |
||
20 | * @return $this |
||
21 | */ |
||
22 | public function fresh() |
||
23 | { |
||
24 | $this->useStateStorage = false; |
||
25 | |||
26 | return $this; |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Returns if the stored state is set to failed or runs the checker |
||
31 | * if nothing is stored and returns wether the checker fails. |
||
32 | * |
||
33 | * @param string $checkerClass |
||
34 | * @return bool |
||
35 | */ |
||
36 | public function isFailing(string $checkerClass): bool |
||
37 | { |
||
38 | if ($this->useStateStorage) { |
||
39 | $storage = CheckerState::make($checkerClass); |
||
40 | |||
41 | if ($storage->exists()) { |
||
42 | return $storage->isFailing(); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | $this->useStateStorage = true; |
||
47 | |||
48 | return Executor::make($checkerClass)->fails(); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * The opposite of the 'isFailing' method. |
||
53 | * |
||
54 | * @param string $checkerClass |
||
55 | * @return bool |
||
56 | */ |
||
57 | public function isPassing(string $checkerClass): bool |
||
60 | } |
||
61 | } |
||
62 |