HistoryHandlerTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 40
ccs 13
cts 13
cp 1
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleHistory() 0 19 3
1
<?php
2
3
namespace Yaro\Jarboe\Http\Controllers\Traits\Handlers;
4
5
use Illuminate\Http\Request;
6
use Spatie\Permission\Exceptions\UnauthorizedException;
7
use Yaro\Jarboe\Exceptions\PermissionDenied;
8
use Yaro\Jarboe\Table\CRUD;
9
10
trait HistoryHandlerTrait
11
{
12
    protected $historyCrudHistory = 'jarboe::crud.history';
13
14
    /**
15
     * Show history page.
16
     *
17
     * @param Request $request
18
     * @param $id
19
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
20
     * @throws PermissionDenied
21
     * @throws UnauthorizedException
22
     */
23 4
    public function handleHistory(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

23
    public function handleHistory(/** @scrutinizer ignore-unused */ Request $request, $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
24
    {
25 4
        $this->beforeInit();
26 4
        $this->init();
27 4
        $this->bound();
28
29 4
        if (!$this->can('history')) {
30 2
            throw UnauthorizedException::forPermissions(['history']);
31
        }
32
33 2
        $model = $this->crud()->repo()->find($id);
34 2
        if (!$this->crud()->actions()->isAllowed('history', $model)) {
35 1
            throw new PermissionDenied();
36
        }
37
38 1
        return view($this->historyCrudHistory, [
39 1
            'crud' => $this->crud(),
40 1
            'item' => $model,
41 1
            'versions' => $model->versions()->latest()->paginate(8),
42
        ]);
43
    }
44
45
    abstract protected function beforeInit();
46
    abstract protected function init();
47
    abstract protected function bound();
48
    abstract protected function crud(): CRUD;
49
    abstract protected function can($action): bool;
50
}
51