SearchHandlerTrait::handleSearch()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
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\Table\CRUD;
8
9
trait SearchHandlerTrait
10
{
11
    /**
12
     * Handle search action.
13
     *
14
     * @param Request $request
15
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
16
     * @throws UnauthorizedException
17
     */
18 3
    public function handleSearch(Request $request)
19
    {
20 3
        $this->beforeInit();
21 3
        $this->init();
22 3
        $this->bound();
23
24 3
        if (!$this->can('search')) {
25 2
            throw UnauthorizedException::forPermissions(['search']);
26
        }
27
28 1
        $this->crud()->saveSearchFilterParams($request->get('search', []));
29
30 1
        return redirect($this->crud()->listUrl());
31
    }
32
33
    abstract protected function beforeInit();
34
    abstract protected function init();
35
    abstract protected function bound();
36
    abstract protected function crud(): CRUD;
37
    abstract protected function can($action): bool;
38
}
39