flashMessages()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 11
rs 10
ccs 0
cts 6
cp 0
cc 3
nc 4
nop 0
crap 12
1
<?php
2
3
use Nip\Container\Container;
4
5
/**
6
 * @param $name
7
 * @return mixed|null
8
 */
9
function flash_get($name)
10
{
11 1
    return flashData()->get($name);
12
}
13
14
/**
15
 * @param $name
16
 * @param $value
17
 */
18
function flash_add($name, $value)
19
{
20
    flashData()->add($name, $value);
21
}
22
23
/**
24
 * @return \Nip\FlashData\FlashData
25
 */
26
function flashData()
27
{
28 1
    if (function_exists('app')) {
29 1
        $container = app();
30
    } else {
31
        $container = Container::getInstance();
32
    }
33 1
    if ($container->has('flash.data') === false) {
34
        throw new Exception("Flash Provider not registered");
35
    }
36 1
    return $container->get('flash.data');
37
}
38
39
/**
40
 * @param $name
41
 * @param $message
42
 */
43
function flash_success($name, $message)
44
{
45
    flashMessages()->add($name, 'success', $message);
46
}
47
48
/**
49
 * @param $name
50
 * @param $message
51
 */
52
function flash_error($name, $message)
53
{
54
    flashMessages()->add($name, 'error', $message);
55
}
56
57
/**
58
 * @param $name
59
 * @param $message
60
 */
61
function flash_info($name, $message)
62
{
63
    flashMessages()->add($name, 'info', $message);
64
}
65
66
/**
67
 * @return \Nip\FlashData\FlashMessages
68
 */
69
function flashMessages()
70
{
71
    if (function_exists('app')) {
72
        $container = app();
73
    } else {
74
        $container = Container::getInstance();
75
    }
76
    if ($container->has('flash.data') === false) {
77
        throw new Exception("Flash Provider not registered");
78
    }
79
    return $container->get('flash.messages');
80
}
81