Behavior::desktopNotify()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2.0078

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 8
cp 0.875
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2.0078
1
<?php
2
/**
3
 * @link https://github.com/vuongxuongminh/yii2-desktop-notifier
4
 * @copyright Copyright (c) 2019 Vuong Xuong Minh
5
 * @license [New BSD License](http://www.opensource.org/licenses/bsd-license.php)
6
 */
7
8
namespace vxm\desktopNotifier;
9
10
use yii\base\Behavior as BaseBehavior;
11
12
use Joli\JoliNotif\Notification;
13
use Joli\JoliNotif\NotifierFactory;
14
15
/**
16
 * Class Behavior
17
 *
18
 * @author Vuong Minh <[email protected]>
19
 * @since 1.0.0
20
 */
21
class Behavior extends BaseBehavior
22
{
23
    /**
24
     * Send desktop notify
25
     *
26
     * @param string $title of notice
27
     * @param string $body content of notice message
28
     * @param null $icon of notice
29
     */
30 1
    public function desktopNotify(string $title, string $body, $icon = null)
31
    {
32 1
        $notification = new Notification();
33 1
        $notification->setTitle($title);
34 1
        $notification->setBody($body);
35
36 1
        if ($icon !== null) {
37
            $notification->setIcon($icon);
38
        }
39
40 1
        NotifierFactory::create()->send($notification);
41 1
    }
42
43
}
44