Notices::getNotices()   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
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Notices class file
4
 *
5
 * @package EBloodBank
6
 * @since   1.0
7
 */
8
namespace EBloodBank;
9
10
/**
11
 * Notices class
12
 *
13
 * @since 1.0
14
 */
15
class Notices
16
{
17
    /**
18
     * The notices list.
19
     *
20
     * @var array
21
     * @since 1.0
22
     * @static
23
     */
24
    private static $notices = [];
25
26
    /**
27
     * @access private
28
     * @since 1.0
29
     */
30
    private function __construct()
31
    {
32
    }
33
34
    /**
35
     * Get all notices.
36
     *
37
     * @return array
38
     * @since 1.0
39
     * @static
40
     */
41
    public static function getNotices()
42
    {
43
        return self::$notices;
44
    }
45
46
    /**
47
     * Get a notice.
48
     *
49
     * @return object
50
     * @since 1.0
51
     * @static
52
     */
53
    public static function getNotice($code)
54
    {
55
        if (self::isExists($code)) {
56
            return self::$notices[$code];
57
        }
58
    }
59
60
    /**
61
     * Whether a given notice is exists.
62
     *
63
     * @return bool
64
     * @since 1.0
65
     * @static
66
     */
67
    public static function isExists($code)
68
    {
69
        return isset(self::$notices[$code]);
70
    }
71
72
    /**
73
     * Add a new notice.
74
     *
75
     * @return bool
76
     * @since 1.0
77
     * @static
78
     */
79
    public static function addNotice($code, $msg, $type = 'warning')
80
    {
81
        if (! $code || self::isExists($code)) {
82
            return false;
83
        }
84
85
        self::$notices[$code] = (object) [
86
            'code' => $code,
87
            'type' => $type,
88
            'msg'  => $msg,
89
        ];
90
91
        return true;
92
    }
93
94
    /**
95
     * Remove an existing notice.
96
     *
97
     * @return void
98
     * @since 1.0
99
     * @static
100
     */
101
    public static function removeNotice($code)
102
    {
103
        if (! $code || ! self::isExists($code)) {
104
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type void.
Loading history...
105
        }
106
107
        unset(self::$notices[$code]);
108
109
        return true;
0 ignored issues
show
Bug Best Practice introduced by
The expression return true returns the type true which is incompatible with the documented return type void.
Loading history...
110
    }
111
}
112