Completed
Push — version-4 ( a26cca...5903bf )
by
unknown
02:38
created

MultipleSender   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 33
rs 10
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 20 2
1
<?php
2
3
namespace Fenos\Notifynder\Senders;
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
38
        return $insert;
39
    }
40
}
41