ToolbarHandlerTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 8
cp 0
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A toolbar() 0 13 2
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