BaseApplication   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 83
Duplicated Lines 19.28 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 16
loc 83
rs 10
c 0
b 0
f 0
wmc 11
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
getRepositoryInterface() 0 1 ?
A getCurrentUser() 0 4 1
A setCurrentUser() 0 6 1
C resource() 16 61 9

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 Bludata\Lumen\Application;
4
5
use Closure;
6
use Laravel\Lumen\Application;
7
8
abstract class BaseApplication extends Application
9
{
10
    protected $currentUser;
11
12
    abstract public function getRepositoryInterface($entity);
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...
13
14
    public function getCurrentUser()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
15
    {
16
        return $this->currentUser;
17
    }
18
19
    public function setCurrentUser($currentUser)
20
    {
21
        $this->currentUser = $currentUser;
22
23
        return $this;
24
    }
25
26
    /**
27
     * @return Bludata\Lumen\Application\BaseApplication
0 ignored issues
show
Documentation introduced by
Should the return type not be BaseApplication?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
28
     */
29
    public function resource($descriptionGroup, $prefix, $controller, array $except = [], Closure $routes = null)
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 113 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
30
    {
31
        $exceptAll = false;
32
33
        if (isset($except[0])) {
34
            $exceptAll = $except[0] == '*';
35
        }
36
37
        if (!$exceptAll) {
38 View Code Duplication
            if (!in_array('index', $except)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
39
                $this->get($prefix, [
40
                    'as'               => $prefix.'.index',
41
                    'uses'             => $controller.'@index',
42
                    'description'      => 'Buscar todos',
43
                    'descriptionGroup' => $descriptionGroup,
44
                ]);
45
            }
46
47
            if (!in_array('show', $except)) {
48
                $this->get($prefix.'/{id:[0-9]+}', [
49
                    'as'               => $prefix.'.show',
50
                    'uses'             => $controller.'@show',
51
                    'description'      => 'Buscar um',
52
                    'descriptionGroup' => $descriptionGroup,
53
                ]);
54
            }
55
56
            if (!in_array('store', $except)) {
57
                $this->post($prefix, [
58
                    'as'               => $prefix.'.store',
59
                    'uses'             => $controller.'@store',
60
                    'description'      => 'Cadastrar',
61
                    'descriptionGroup' => $descriptionGroup,
62
                ]);
63
            }
64
65 View Code Duplication
            if (!in_array('update', $except)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
66
                $this->put($prefix.'/{id:[0-9]+}', [
67
                    'as'               => $prefix.'.update',
68
                    'uses'             => $controller.'@update',
69
                    'description'      => 'Editar',
70
                    'descriptionGroup' => $descriptionGroup,
71
                ]);
72
            }
73
74
            if (!in_array('destroy', $except)) {
75
                $this->delete($prefix.'/{id:[0-9]+}', [
76
                    'as'               => $prefix.'.destroy',
77
                    'uses'             => $controller.'@destroy',
78
                    'description'      => 'Excluir',
79
                    'descriptionGroup' => $descriptionGroup,
80
                ]);
81
            }
82
        }
83
84
        if ($routes instanceof Closure) {
85
            $routes($descriptionGroup, $prefix, $controller);
86
        }
87
88
        return $this;
89
    }
90
}
91