Passed
Push — master ( d1c6ec...66cfc7 )
by Iman
06:37
created

CRUD   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 5 1
A create() 0 4 1
A update() 0 4 1
A insertLog() 0 3 2
A deleteImage() 0 6 1
A registerListeners() 0 6 1
1
<?php
2
3
namespace crocodicstudio\crudbooster\Modules\LogsModule\Listeners;
4
5
use crocodicstudio\crudbooster\CBCoreModule\CbUser;
6
use crocodicstudio\crudbooster\Modules\LogsModule\LogsRepository;
7
8
class CRUD
9
{
10
    public static function registerListeners()
11
    {
12
        self::delete();
13
        self::update();
14
        self::create();
15
        self::deleteImage();
16
    }
17
18
    private static function delete()
19
    {
20
        Event::listen('cb.dataDeleted', function (string $table, array $ids, string $time, CbUser $user) {
0 ignored issues
show
Bug introduced by
The type crocodicstudio\crudboost...sModule\Listeners\Event was not found. Did you mean Event? If so, make sure to prefix the type with \.
Loading history...
21
            $ids = implode(', ', $ids);
22
            self::insertLog("Data deleted from $table table with Ids: $ids at $time", $user->id);
23
        });
24
    }
25
26
    private static function insertLog($description, $userId = null)
27
    {
28
        LogsRepository::insertLog('crudbooster: '.$description, $userId ?: auth('cbAdmin')->id());
29
    }
30
31
    private static function create()
32
    {
33
        Event::listen('cb.dataInserted', function (string $table, int $id, string $time, CbUser $user) {
34
            self::insertLog("Data inserted into $table table with Id: $id at $time", $user->id);
35
        });
36
    }
37
38
    private static function update()
39
    {
40
        Event::listen('cb.dataUpdated', function (string $table, int $id, string $time, CbUser $user) {
41
            self::insertLog("Data updated within $table table with Id: $id at $time", $user->id);
42
        });
43
    }
44
45
    private static function deleteImage()
46
    {
47
        Event::listen('cb.imageDeleted', function (string $table, array $prop, string $time, CbUser $user) {
48
            $file = $prop['file'];
49
            $id = $prop['id'];
50
            self::insertLog("($file) Image deleted from $table table with Id: $id at $time", $user->id);
51
        });
52
    }
53
}