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

ListHandlerTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.86%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 51
loc 51
ccs 13
cts 14
cp 0.9286
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A handleList() 16 16 2
A getListViewsAbove() 4 4 1
A getListViewsBelow() 4 4 1
init() 1 1 ?
bound() 1 1 ?
crud() 1 1 ?
can() 1 1 ?

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 View Code Duplication
trait ListHandlerTrait
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
10
{
11
    /**
12
     * Show table list page.
13
     *
14
     * @param Request $request
15
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
16
     * @throws UnauthorizedException
17
     */
18 1
    public function handleList(Request $request)
19
    {
20 1
        $this->init();
21 1
        $this->bound();
22
23 1
        if (!$this->can('list')) {
24
            throw UnauthorizedException::forPermissions(['list']);
25
        }
26
27 1
        return view($this->viewCrudList, [
0 ignored issues
show
Bug introduced by
The property viewCrudList does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
28 1
            'crud' => $this->crud(),
29 1
            'items' => $this->crud()->repo()->get(),
30 1
            'viewsAbove' => $this->getListViewsAbove(),
31 1
            'viewsBelow' => $this->getListViewsBelow(),
32
        ]);
33
    }
34
35
    /**
36
     * Get array of view's objects, that should be rendered above content of `list` view.
37
     *
38
     * @return array
39
     */
40 2
    protected function getListViewsAbove(): array
41
    {
42 2
        return [];
43
    }
44
45
    /**
46
     * Get array of view's objects, that should be rendered below content of `list` view.
47
     *
48
     * @return array
49
     */
50 2
    protected function getListViewsBelow(): array
51
    {
52 2
        return [];
53
    }
54
55
    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...
56
    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...
57
    abstract protected function crud(): CRUD;
58
    abstract protected function can($action): bool;
59
}
60