Test Failed
Branch v5 (12d602)
by Alexey
04:51
created

Msg   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
B add() 0 18 5
A show() 0 3 1
A get() 0 9 3
A flush() 0 3 1
1
<?php
2
namespace Inji;
3
/**
4
 * Msg
5
 *
6
 * @author Alexey Krupskiy <[email protected]>
7
 * @link http://inji.ru/
8
 * @copyright 2015 Alexey Krupskiy
9
 * @license https://github.com/injitools/cms-Inji/blob/master/LICENSE
10
 */
11
class Msg extends Module {
12
13
    /**
14
     * Add message to query
15
     * 
16
     * @param string $text
17
     * @param string $status
18
     */
19
    public static function add($text = false, $status = 'info') {
20
        if ($text !== false) {
21
            if (!empty($_SESSION['_INJI_MSG'])) {
22
                foreach ($_SESSION['_INJI_MSG'] as $key => $msg) {
23
                    if ($msg['text'] == $text) {
24
                        $msg['count']++;
25
                        return true;
26
                    }
27
                }
28
            }
29
            $_SESSION['_INJI_MSG'][] = [
30
                'text' => $text,
31
                'status' => $status,
32
                'count' => 1
33
            ];
34
        }
35
        return true;
36
    }
37
38
    /**
39
     * Show messages query
40
     */
41
    public static function show() {
42
        App::$cur->view->widget('msgList');
43
    }
44
45
    /**
46
     * Get cur messages query
47
     * 
48
     * @param boolean $clean
49
     * @return array
50
     */
51
    public static function get($clean = false) {
52
        if (empty($_SESSION['_INJI_MSG']))
53
            return [];
54
        $msgs = $_SESSION['_INJI_MSG'];
55
        if ($clean) {
56
            $_SESSION['_INJI_MSG'] = [];
57
        }
58
        return $msgs;
59
    }
60
61
    /**
62
     * Clean messages query
63
     */
64
    public static function flush() {
65
        $_SESSION['_INJI_MSG'] = [];
66
    }
67
68
}
69