| Total Complexity | 11 |
| Total Lines | 84 |
| Duplicated Lines | 0 % |
| Changes | 5 | ||
| Bugs | 1 | Features | 3 |
| 1 | <?php |
||
| 8 | class StatusCheckerGroup implements LoggerAwareInterface |
||
| 9 | { |
||
| 10 | use LoggerAwareTrait; |
||
| 11 | |||
| 12 | /** @var string */ |
||
| 13 | protected $title; |
||
| 14 | |||
| 15 | /** @var CheckInterface[] */ |
||
| 16 | protected $checks = []; |
||
| 17 | |||
| 18 | /** @var Result[] */ |
||
| 19 | protected $results = []; |
||
| 20 | |||
| 21 | |||
| 22 | /** |
||
| 23 | * StatusCheckerGroup constructor. |
||
| 24 | * @param string $title |
||
| 25 | */ |
||
| 26 | public function __construct(string $title) |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public function getTitle(): string |
||
| 35 | { |
||
| 36 | return $this->title; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Adds check to the group. |
||
| 41 | * |
||
| 42 | * @param CheckInterface $checker |
||
| 43 | */ |
||
| 44 | public function addCheck(CheckInterface $checker): void |
||
| 45 | { |
||
| 46 | $this->checks[] = $checker; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Runs all added checks. |
||
| 51 | */ |
||
| 52 | public function check(): void |
||
| 53 | { |
||
| 54 | foreach ($this->checks as $checker) { |
||
| 55 | $result = $checker->checkStatus(); |
||
| 56 | if ($this->logger) { |
||
| 57 | if ($result->isSuccess()) { |
||
| 58 | $this->logger->info($result->getLabel().': OK', ['details' => $result->getDetails()]); |
||
| 59 | } else { |
||
| 60 | $this->logger->alert($result->getLabel().': '.$result->getError(), ['details' => $result->getDetails()]); |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $this->results[] = $result; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Returns results of all run checks. |
||
| 69 | * |
||
| 70 | * @return Result[] |
||
| 71 | */ |
||
| 72 | public function getResults(): array |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Returns if there is an erroneous result in this group. |
||
| 79 | * |
||
| 80 | * @return bool |
||
| 81 | */ |
||
| 82 | public function hasErrors(): bool |
||
| 94 |