Completed
Push — master ( 665333...49dc1a )
by Yaro
18:38 queued 08:40
created

HistoryHandlerTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 0
loc 41
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A handleHistory() 0 21 3
beforeInit() 0 1 ?
init() 0 1 ?
bound() 0 1 ?
crud() 0 1 ?
can() 0 1 ?
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
    public function handleHistory(Request $request, $id)
24
    {
25
        $this->beforeInit();
26
        $this->init();
27
        $this->bound();
28
29
        if (!$this->can('history')) {
30
            throw UnauthorizedException::forPermissions(['history']);
31
        }
32
33
        $model = $this->crud()->repo()->find($id);
34
        if (!$this->crud()->actions()->isAllowed('history', $model)) {
35
            throw new PermissionDenied();
36
        }
37
38
        return view($this->historyCrudHistory, [
39
            'crud' => $this->crud(),
40
            'item' => $model,
41
            'versions' => $model->versions()->latest()->paginate(8),
42
        ]);
43
    }
44
45
    abstract protected function beforeInit();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
46
    abstract protected function init();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
47
    abstract protected function bound();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
48
    abstract protected function crud(): CRUD;
49
    abstract protected function can($action): bool;
50
}
51