Passed
Push — master ( 3d0d87...075b69 )
by Antonio Carlos
09:13
created

Notification::getSenderInstance()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 1
1
<?php
2
3
namespace PragmaRX\Firewall\Notifications;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Notifications\Notification as IlluminateNotification;
7
8
class Notification extends IlluminateNotification
9
{
10
    use Queueable;
11
12
    /**
13
     * @var
14
     */
15
    private $item;
16
17
    /**
18
     * @var
19
     */
20
    private $channel;
21
22
    /**
23
     * Create a new notification instance.
24
     *
25
     * @param $item
26
     */
27 2
    public function __construct($item, $channel)
28
    {
29 2
        $this->item = $item;
30
31 2
        $this->channel = $channel;
32 2
    }
33
34
    /**
35
     * @param $name
36
     *
37
     * @return \Illuminate\Foundation\Application|mixed
38
     */
39 2
    private function getSenderInstance($name)
40
    {
41 2
        $name = substr($name, 2);
42
43 2
        return app(config('firewall.notifications.channels.'.strtolower($name).'.sender'));
44
    }
45
46
    /**
47
     * Get the notification's delivery channels.
48
     *
49
     * @return array
50
     */
51 2
    public function via()
52
    {
53 2
        return [$this->channel];
54
    }
55
56
    /**
57
     * @param $name
58
     * @param $parameters
59
     *
60
     * @return mixed
61
     */
62 2
    public function __call($name, $parameters)
63
    {
64 2
        $parameters[] = $this->item;
65
66 2
        return call_user_func_array(
67
            [
68 2
                $this->getSenderInstance($name),
69 2
                'send',
70
            ],
71 2
            $parameters
72
        );
73
    }
74
}
75