EditHandlerTrait::getEditViewsBelow()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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 EditHandlerTrait
11
{
12
    protected $viewCrudEdit = 'jarboe::crud.edit';
13
14
    /**
15
     * Show edit form 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 handleEdit(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 handleEdit(/** @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
        $model = $this->crud()->repo()->find($id);
30 4
        if (!$this->crud()->actions()->isAllowed('edit', $model)) {
31 1
            throw new PermissionDenied();
32
        }
33
34 3
        if (!$this->can('edit')) {
35 2
            throw UnauthorizedException::forPermissions(['edit']);
36
        }
37
38 1
        $this->idEntity = $model->getKey();
0 ignored issues
show
Bug Best Practice introduced by
The property idEntity does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
39
40 1
        return view($this->viewCrudEdit, [
41 1
            'crud' => $this->crud(),
42 1
            'item' => $model,
43 1
            'viewsAbove' => $this->getEditViewsAbove(),
44 1
            'viewsBelow' => $this->getEditViewsBelow(),
45
        ]);
46
    }
47
48
    /**
49
     * Get array of view's objects, that should be rendered above content of `edit` view.
50
     *
51
     * @return array
52
     */
53 2
    protected function getEditViewsAbove(): array
54
    {
55 2
        return [];
56
    }
57
58
    /**
59
     * Get array of view's objects, that should be rendered below content of `edit` view.
60
     *
61
     * @return array
62
     */
63 2
    protected function getEditViewsBelow(): array
64
    {
65 2
        return [];
66
    }
67
68
    abstract protected function beforeInit();
69
    abstract protected function init();
70
    abstract protected function bound();
71
    abstract protected function crud(): CRUD;
72
    abstract protected function can($action): bool;
73
}
74