ListHandlerTrait::handleList()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 10
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 15
ccs 11
cts 11
cp 1
crap 2
rs 9.9332
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\Table\CRUD;
8
9
trait ListHandlerTrait
10
{
11
    protected $viewCrudList = 'jarboe::crud.list';
12
13
    /**
14
     * Show table list page.
15
     *
16
     * @param Request $request
17
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
18
     * @throws UnauthorizedException
19
     */
20 4
    public function handleList(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

20
    public function handleList(/** @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...
21
    {
22 4
        $this->beforeInit();
23 4
        $this->init();
24 4
        $this->bound();
25
26 4
        if (!$this->can('list')) {
27 2
            throw UnauthorizedException::forPermissions(['list']);
28
        }
29
30 2
        return view($this->viewCrudList, [
31 2
            'crud' => $this->crud(),
32 2
            'items' => $this->crud()->repo()->get(),
33 2
            'viewsAbove' => $this->getListViewsAbove(),
34 2
            'viewsBelow' => $this->getListViewsBelow(),
35
        ]);
36
    }
37
38
    /**
39
     * Get array of view's objects, that should be rendered above content of `list` view.
40
     *
41
     * @return array
42
     */
43 3
    protected function getListViewsAbove(): array
44
    {
45 3
        return [];
46
    }
47
48
    /**
49
     * Get array of view's objects, that should be rendered below content of `list` view.
50
     *
51
     * @return array
52
     */
53 3
    protected function getListViewsBelow(): array
54
    {
55 3
        return [];
56
    }
57
58
    abstract protected function beforeInit();
59
    abstract protected function init();
60
    abstract protected function bound();
61
    abstract protected function crud(): CRUD;
62
    abstract protected function can($action): bool;
63
}
64