Test Failed
Pull Request — master (#674)
by Orkhan
05:19
created

Database   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 40%

Importance

Changes 7
Bugs 0 Features 2
Metric Value
eloc 14
c 7
b 0
f 2
dl 0
loc 32
ccs 6
cts 15
cp 0.4
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A audit() 0 5 1
A prune() 0 17 3
1
<?php
2
3
namespace OwenIt\Auditing\Drivers;
4
5
use Illuminate\Support\Facades\Config;
6
use OwenIt\Auditing\Contracts\Audit;
7
use OwenIt\Auditing\Contracts\Auditable;
8
use OwenIt\Auditing\Contracts\AuditDriver;
9
10
class Database implements AuditDriver
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 12
    public function audit(Auditable $model): Audit
16
    {
17 12
        $implementation = Config::get('audit.implementation', \OwenIt\Auditing\Models\Audit::class);
18
19 12
        return call_user_func([$implementation, 'create'], $model->toAudit());
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 12
    public function prune(Auditable $model): bool
26
    {
27 12
        if (($threshold = $model->getAuditThreshold()) > 0) {
28
            $forRemoval = $model->audits()
29
                ->latest()
30
                ->get()
31
                ->slice($threshold)
32
                ->pluck('id');
33
34
            if (!$forRemoval->isEmpty()) {
35
                return $model->audits()
36
                    ->whereIn('id', $forRemoval)
37
                    ->delete() > 0;
38
            }
39
        }
40
41 12
        return false;
42
    }
43
}
44