Passed
Push — master ( fc0856...e4fdff )
by Sugeng
02:03
created

Toastr::run()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 5
c 0
b 0
f 0
nc 4
nop 0
dl 0
loc 8
rs 9.6111
1
<?php
2
3
namespace diecoding\toastr;
4
5
use yii\helpers\Json;
6
7
/**
8
 * Toastr widget
9
 * 
10
 * @link [sugeng-sulistiyawan.github.io](sugeng-sulistiyawan.github.io)
11
 * @author Sugeng Sulistiyawan <[email protected]>
12
 * @copyright Copyright (c) 2023
13
 */
14
class Toastr extends ToastrBase
15
{
16
    /**
17
     *
18
     * @var string
19
     */
20
    public $type;
21
22
    /**
23
     *
24
     * @var string
25
     */
26
    public $title;
27
28
    /**
29
     *
30
     * @var string
31
     */
32
    public $message;
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function run()
38
    {
39
        $type    = $this->type && in_array($this->type, self::TYPES) ? $this->type : $this->typeDefault;
40
        $title   = $this->title ?: $this->titleDefault;
41
        $message = $this->message ?: $this->messageDefault;
42
        $options = Json::encode($this->options);
43
44
        $this->view->registerJs("toastr.{$type}(\"{$message}\", \"{$title}\", {$options});");
45
    }
46
}
47