Completed
Push — master ( f066c0...72d72a )
by Yaro
01:50 queued 10s
created

SearchHandlerTrait::handleSearch()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 6
cts 7
cp 0.8571
rs 9.8333
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2.0116
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 1
    public function handleSearch(Request $request)
19
    {
20 1
        $this->init();
21 1
        $this->bound();
22
23 1
        if (!$this->can('search')) {
24
            throw UnauthorizedException::forPermissions(['search']);
25
        }
26
27 1
        $this->crud()->saveSearchFilterParams($request->get('search', []));
28
29 1
        return redirect($this->crud()->listUrl());
30
    }
31
32
    abstract protected function init();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
33
    abstract protected function bound();
0 ignored issues
show
Documentation introduced by
For interfaces and abstract methods it is generally a good practice to add a @return annotation even if it is just @return void or @return null, so that implementors know what to do in the overridden method.

For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a @return doc comment to communicate to implementors of these methods what they are expected to return.

Loading history...
34
    abstract protected function crud(): CRUD;
35
    abstract protected function can($action): bool;
36
}
37