Notification::notification()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: floor12
5
 * Date: 24.06.2018
6
 * Time: 12:51
7
 */
8
9
namespace floor12\notification;
10
11
use yii\helpers\Html;
12
use \Yii;
13
14
/**
15
 * Class Notification
16
 * Its a notification php helper class. It registers AssetBundle in a view and runs Js function.
17
 * @package floor12\notification
18
 */
19
class Notification
20
{
21
22
    const TYPE_INFO = "0";
23
    const TYPE_SUCCESS = "1";
24
    const TYPE_ERROR = "2";
25
26
    /**Registers AssetBundle in a view.
27
     * Returns string with Javascript info() function call.
28
     * @param $text
29
     * @param $type
30
     * @return string
31
     */
32
    public static function notification($text, $type): string
33
    {
34
        NotificationAsset::register(Yii::$app->getView());
35
        return Html::script("info(\"{$text}\",{$type});");
36
    }
37
38
    /** Alias to self::notification with INFO type.
39
     * @param $text
40
     * @return string
41
     */
42
    public static function info($text): string
43
    {
44
        return self::notification($text, self::TYPE_INFO);
45
    }
46
47
    /** Alias to self::notification with ERROR type.
48
     * @param $text
49
     * @return string
50
     */
51
    public static function error($text): string
52
    {
53
        return self::notification($text, self::TYPE_ERROR);
54
    }
55
56
    /** Alias to self::notification with SUCCESS type.
57
     * @param $text
58
     * @return string
59
     */
60
    public static function success($text): string
61
    {
62
        return self::notification($text, self::TYPE_SUCCESS);
63
    }
64
65
}