Test Setup Failed
Push — dependabot/npm_and_yarn/larave... ( c86056...82b153 )
by
unknown
220:25 queued 213:07
created

ToastNotifier::generateUniqueSessionKey()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 9
rs 10
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Thinktomorrow\Chief\System\HealthMonitor\Notifiers;
6
7
use Thinktomorrow\Chief\System\HealthMonitor\Checks\HealthCheck;
8
9
class ToastNotifier implements Notifier
10
{
11
    public function onFailure(HealthCheck $healthCheck)
12
    {
13
        session()->now($this->generateUniqueSessionKey(), ['type' => 'warning', 'message' => $healthCheck->message() ]);
14
    }
15
16
    public function onSuccess(HealthCheck $healthCheck)
17
    {
18
    }
19
20
    private function generateUniqueSessionKey(): string
21
    {
22
        $toastId = 'toast_messages.' . mt_rand(0, 9999);
23
24
        while (session()->get($toastId)) {
25
            $toastId = 'toast_messages.' . mt_rand(0, 9999);
26
        }
27
28
        return $toastId;
29
    }
30
}
31