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::setSearch()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
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