Alert   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 40
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 10 2
A getAlerts() 0 4 1
1
<?php
2
3
namespace app\helpers;
4
5
use Yii;
6
7
class Alert
8
{
9
    const INFO = 'info';
10
    const SUCCESS = 'success';
11
    const WARNING = 'warning';
12
    const DANGER = 'danger';
13
    const ALERT_TYPES = [
14
        self::INFO,
15
        self::SUCCESS,
16
        self::WARNING,
17
        self::DANGER,
18
    ];
19
20
    /**
21
     * Create a new flash alert used for displaying info to users.
22
     *
23
     * @param string $message alert message content
24
     * @param string $type    alert type
25
     */
26
    public static function add($message, $type = self::INFO)
27
    {
28
        if (in_array($type, self::ALERT_TYPES)) {
29
            Yii::$app->session->addFlash('alert', ['type' => $type, 'message' => Yii::t('app', $message)]);
30
31
            return true;
32
        }
33
34
        return false;
35
    }
36
37
    /**
38
     * Retrieve previously added alerts to display them.
39
     *
40
     * @return array alerts
41
     */
42
    public static function getAlerts()
43
    {
44
        return Yii::$app->session->getFlash('alert', []);
45
    }
46
}
47