CreateHandlerTrait   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 58
ccs 16
cts 16
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreateViewsAbove() 0 3 1
A getCreateViewsBelow() 0 3 1
A handleCreate() 0 18 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 CreateHandlerTrait
11
{
12
    protected $viewCrudCreate = 'jarboe::crud.create';
13
14
    /**
15
     * Show create form page.
16
     *
17
     * @param Request $request
18
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
19
     * @throws PermissionDenied
20
     * @throws UnauthorizedException
21
     */
22 4
    public function handleCreate(Request $request)
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

22
    public function handleCreate(/** @scrutinizer ignore-unused */ Request $request)

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...
23
    {
24 4
        $this->beforeInit();
25 4
        $this->init();
26 4
        $this->bound();
27
28 4
        if (!$this->crud()->actions()->isAllowed('create')) {
29 1
            throw new PermissionDenied();
30
        }
31
32 3
        if (!$this->can('create')) {
33 2
            throw UnauthorizedException::forPermissions(['create']);
34
        }
35
36 1
        return view($this->viewCrudCreate, [
37 1
            'crud' => $this->crud(),
38 1
            'viewsAbove' => $this->getCreateViewsAbove(),
39 1
            'viewsBelow' => $this->getCreateViewsBelow(),
40
        ]);
41
    }
42
43
    /**
44
     * Get array of view's objects, that should be rendered above content of `create` view.
45
     *
46
     * @return array
47
     */
48 2
    protected function getCreateViewsAbove(): array
49
    {
50 2
        return [];
51
    }
52
53
    /**
54
     * Get array of view's objects, that should be rendered below content of `create` view.
55
     *
56
     * @return array
57
     */
58 2
    protected function getCreateViewsBelow(): array
59
    {
60 2
        return [];
61
    }
62
63
    abstract protected function beforeInit();
64
    abstract protected function init();
65
    abstract protected function bound();
66
    abstract protected function crud(): CRUD;
67
    abstract protected function can($action): bool;
68
}
69