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

Toastr   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 31
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 8 5
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