Completed
Push — version-4 ( 511c26...6005c1 )
by
unknown
02:14
created

MultipleSender::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
eloc 15
c 1
b 0
f 1
nc 2
nop 1
dl 0
loc 19
rs 9.4285
1
<?php
2
namespace Fenos\Notifynder\Senders;
3
4
5
use Fenos\Notifynder\Contracts\SenderContract;
6
use Fenos\Notifynder\Contracts\SenderManagerContract;
7
8
class MultipleSender implements SenderContract
9
{
10
    protected $notifications;
11
12
    protected $database;
13
14
    public function __construct(array $notifications)
15
    {
16
        $this->notifications = $notifications;
17
        $this->database = app('db');
18
    }
19
20
    public function send(SenderManagerContract $sender)
21
    {
22
        $model = notifynder_config()->getNotificationModel();
23
        $table = (new $model())->getTable();
24
25
        $this->database->beginTransaction();
26
        $stackId = $this->database
27
                ->table($table)
28
                ->max('stack_id') + 1;
29
        foreach ($this->notifications as $key => $notification) {
30
            $this->notifications[$key] = $this->notifications[$key]->toArray();
31
            $this->notifications[$key]['stack_id'] = $stackId;
32
        }
33
        $insert = $this->database
34
            ->table($table)
35
            ->insert($this->notifications);
36
        $this->database->commit();
37
        return $insert;
38
    }
39
}