ToolbarHandlerTrait::toolbar()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 13
ccs 0
cts 8
cp 0
crap 6
rs 10
1
<?php
2
3
namespace Yaro\Jarboe\Http\Controllers\Traits\Handlers;
4
5
use Illuminate\Http\Request;
6
use Yaro\Jarboe\Exceptions\PermissionDenied;
7
use Yaro\Jarboe\Table\CRUD;
8
use Yaro\Jarboe\Table\Toolbar\Interfaces\ToolInterface;
9
10
trait ToolbarHandlerTrait
11
{
12
    /**
13
     * Handle toolbar's tool request.
14
     *
15
     * @param Request $request
16
     * @param $identifier
17
     * @return mixed
18
     * @throws PermissionDenied
19
     */
20
    public function toolbar(Request $request, $identifier)
21
    {
22
        $this->beforeInit();
23
        $this->init();
24
        $this->bound();
25
26
        /** @var ToolInterface $tool */
27
        $tool = $this->crud()->getTool($identifier);
28
        if (!$tool->check()) {
29
            throw new PermissionDenied();
30
        }
31
32
        return $tool->handle($request);
33
    }
34
35
    abstract protected function beforeInit();
36
    abstract protected function init();
37
    abstract protected function bound();
38
    abstract protected function crud(): CRUD;
39
}
40