GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#688)
by
unknown
18:52
created

SelectAjax   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 27.68 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 19.15%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 31
loc 112
ccs 9
cts 47
cp 0.1915
rs 10
c 1
b 1
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A registerRoutes() 11 11 2
A __construct() 12 12 1
A getSearch() 0 8 2
A setSearch() 0 6 1
A setSearchUrl() 0 6 1
A mutateOptions() 0 4 1
A getSearchUrl() 8 8 2
A toArray() 0 15 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 SleepingOwl\Admin\Form\Element;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Database\Eloquent\Builder;
7
use SleepingOwl\Admin\Contracts\Initializable;
8
use SleepingOwl\Admin\Contracts\WithRoutesInterface;
9
use SleepingOwl\Admin\Contracts\Repositories\RepositoryInterface;
10
11
class SelectAjax extends Select implements Initializable, WithRoutesInterface
12
{
13
    protected static $route = 'selectajax';
14
    protected $view = 'form.element.selectajax';
15
    protected $search_url = null;
16
    protected $search = null;
17
18
    /**
19
     * @param string $path
20
     * @param string|null $label
21
     */
22 View Code Duplication
    public function __construct($path, $label = null)
0 ignored issues
show
Duplication introduced by
This method 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...
23
    {
24
        parent::__construct($path, $label);
25
26
        $this->setLoadOptionsQueryPreparer(function ($item, Builder $query) {
27
            $repository = app(RepositoryInterface::class);
28
            $repository->setModel($this->getModelForOptions());
29
            $key = $repository->getModel()->getKeyName();
30
31
            return $query->where([$key => $this->getValueFromModel()]);
32
        });
33
    }
34
35
    /**
36
     * @param Router $router
37
     */
38 285 View Code Duplication
    public static function registerRoutes(Router $router)
0 ignored issues
show
Duplication introduced by
This method 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...
39
    {
40 285
        $routeName = 'admin.form.element.'.static::$route;
41
42 285
        if (! $router->has($routeName)) {
43 285
            $router->post('{adminModel}/'.static::$route.'/{field}/{id?}', [
44 285
                'as'   => $routeName,
45 285
                'uses' => 'SleepingOwl\Admin\Http\Controllers\FormElementController@selectSearch',
46 285
            ]);
47 285
        }
48 285
    }
49
50
    /**
51
     * @return null
52
     */
53
    public function getSearch()
54
    {
55
        if ($this->search) {
56
            return $this->search;
57
        }
58
59
        return $this->getDisplay();
60
    }
61
62
    /**
63
     * @param $search
64
     * @return $this
65
     */
66
    public function setSearch($search)
67
    {
68
        $this->search = $search;
69
70
        return $this;
71
    }
72
73
    /**
74
     * @param $url
75
     * @return $this
76
     */
77
    public function setSearchUrl($url)
78
    {
79
        $this->search_url = $url;
80
81
        return $this;
82
    }
83
84
    /**
85
     * @return array
86
     */
87
    public function mutateOptions()
88
    {
89
        return $this->getOptions();
90
    }
91
92
    /**
93
     * @return string
94
     */
95 View Code Duplication
    public function getSearchUrl()
0 ignored issues
show
Duplication introduced by
This method 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...
96
    {
97
        return $this->search_url ? $this->search_url : route('admin.form.element.'.static::$route, [
98
            'adminModel' => \AdminSection::getModel($this->model)->getAlias(),
99
            'field'      => $this->getName(),
100
            'id'         => $this->model->getKey(),
101
        ]);
102
    }
103
104
    /**
105
     * @return array
106
     */
107
    public function toArray()
108
    {
109
        $attributes = [
110
            'id'               => $this->getName(),
111
            'size'             => 2,
112
            'data-select-type' => 'single',
113
            'class'            => 'form-control js-data-ajax',
114
            'model'            => get_class($this->getModelForOptions()),
115
            'field'            => $this->getDisplay(),
116
            'search'           => $this->getSearch(),
117
            'search_url'       => $this->getSearchUrl(),
118
        ];
119
120
        return ['attributes' => $attributes] + parent::toArray();
121
    }
122
}
123