Notification   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 10
c 1
b 0
f 0
dl 0
loc 58
ccs 19
cts 19
cp 1
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A addSuccess() 0 3 1
A addInfo() 0 3 1
A getNotify() 0 6 2
A addWarning() 0 3 1
A init() 0 3 1
A addError() 0 3 1
1
<?php
2
3
namespace kalanis\kw_notify;
4
5
6
use kalanis\kw_notify\Interfaces\INotify;
7
8
9
/**
10
 * Class Notification
11
 * @package kalanis\kw_notify
12
 * Notifications
13
 */
14
class Notification
15
{
16
    protected static ?INotify $storage = null;
17
18
    /**
19
     * @param INotify $storage
20
     */
21 1
    public static function init(INotify $storage): void
22
    {
23 1
        static::$storage = $storage;
24 1
    }
25
26
    /**
27
     * @param string $message
28
     * @throws NotifyException
29
     */
30 2
    public static function addInfo(string $message): void
31
    {
32 2
        static::getNotify()->add(INotify::TARGET_INFO, $message);
33 1
    }
34
35
    /**
36
     * @param string $message
37
     * @throws NotifyException
38
     */
39 1
    public static function addError(string $message): void
40
    {
41 1
        static::getNotify()->add(INotify::TARGET_ERROR, $message);
42 1
    }
43
44
    /**
45
     * @param string $message
46
     * @throws NotifyException
47
     */
48 1
    public static function addWarning(string $message): void
49
    {
50 1
        static::getNotify()->add(INotify::TARGET_WARNING, $message);
51 1
    }
52
53
    /**
54
     * @param string $message
55
     * @throws NotifyException
56
     */
57 1
    public static function addSuccess(string $message): void
58
    {
59 1
        static::getNotify()->add(INotify::TARGET_SUCCESS, $message);
60 1
    }
61
62
    /**
63
     * @throws NotifyException
64
     * @return INotify
65
     */
66 2
    public static function getNotify(): INotify
67
    {
68 2
        if (empty(static::$storage)) {
69 1
            throw new NotifyException('You must set notification library first!');
70
        }
71 1
        return static::$storage;
72
    }
73
}
74