Passed
Branch master (3eb6ea)
by Anton
06:04
created

ActiveRecordChannel::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @copyright Anton Tuyakhov <[email protected]>
4
 */
5
6
namespace tuyakhov\notifications\channels;
7
8
9
use tuyakhov\notifications\messages\DatabaseMessage;
10
use tuyakhov\notifications\NotifiableInterface;
11
use tuyakhov\notifications\NotificationInterface;
12
use yii\base\Component;
13
use yii\db\ActiveRecordInterface;
14
use yii\di\Instance;
15
16
class ActiveRecordChannel extends Component implements ChannelInterface
17
{
18
    /**
19
     * @var ActiveRecordInterface|string
20
     */
21
    public $model = 'tuyakhov\notifications\models\DatabaseNotification';
22
23
    /**
24
     * @throws \yii\base\InvalidConfigException
25
     */
26
    public function init()
27
    {
28
        parent::init();
29
        $this->model = Instance::ensure($this->model, 'yii\db\ActiveRecordInterface');
30
    }
31
32
    public function send(NotifiableInterface $recipient, NotificationInterface $notification)
33
    {
34
        /** @var DatabaseMessage $message */
35
        $message = $notification->exportFor('database');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 29 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
36
        list($notifiableType, $notifiableId) = $recipient->routeNotificationFor('database');
37
        $this->model->insert(true, [
38
            'level' => $message->level,
39
            'subject' => $message->subject,
40
            'body' => $message->body,
41
            'notifiable_type' => $notifiableType,
42
            'notifiable_id' => $notifiableId,
43
        ]);
44
    }
45
}