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
Push — bs4 ( 193743...d4da84 )
by butschster
20:32 queued 14:27
created

SelectAjax::mutateOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
use AdminSection;
0 ignored issues
show
Bug introduced by
The type AdminSection was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use Illuminate\Routing\Router;
7
use Illuminate\Database\Eloquent\Builder;
8
use SleepingOwl\Admin\Contracts\Initializable;
9
use SleepingOwl\Admin\Traits\SelectAjaxFunctions;
10
use SleepingOwl\Admin\Contracts\WithRoutesInterface;
11
use SleepingOwl\Admin\Contracts\Repositories\RepositoryInterface;
12
13
class SelectAjax extends Select implements Initializable, WithRoutesInterface
14
{
15
    use SelectAjaxFunctions;
16
17
    protected static $route = 'selectajax';
18
    protected $view = 'form.element.selectajax';
19
20
    /**
21
     * @var string|null
22
     */
23
    protected $language;
24
25
    /**
26
     * SelectAjax constructor.
27
     * @param $path
28
     * @param null $label
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $label is correct as it would always require null to be passed?
Loading history...
29
     * @throws \SleepingOwl\Admin\Exceptions\Form\Element\SelectException
30
     * @throws \SleepingOwl\Admin\Exceptions\Form\FormElementException
31
     */
32
    public function __construct($path, $label = null)
33
    {
34
        parent::__construct($path, $label);
35
36
        /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
        // This code add closure, that modify query so, that select will have only one value.
38
        // This feature need for optimized selectajax initiation for also existing records.
39
        // Make some changes for availability to use setLoadOptionsQueryPreparer() in Sections.
40
        $this->setLoadOptionsQueryPreparer(function ($item, Builder $query) {
41
            $repository = app(RepositoryInterface::class);
42
            $repository->setModel($this->getModelForOptions());
43
            $key = $repository->getModel()->getKeyName();
44
45
            $return = $query->where([$key => $this->getValueFromModel()]);
46
            return $return;
47
        });
48
        */
49
50
        $this->default_query_preparer = function ($item, Builder $query) {
51
            $repository = app(RepositoryInterface::class);
52
            $repository->setModel($this->getModelForOptions());
53
            $key = $repository->getModel()->getKeyName();
54
55
            return $query->where([$key => $this->getValueFromModel()]);
56
        };
57
58
        $this->setLanguage(config('app.locale'));
59
    }
60
61
    /**
62
     * @return string|null
63
     */
64
    public function getLanguage()
65
    {
66
        return $this->language;
67
    }
68
69
    /**
70
     * @param $language
71
     * @return $this
72
     */
73
    public function setLanguage($language)
74
    {
75
        $this->language = $language;
76
77
        return $this;
78
    }
79
80
    /**
81
     * @param Router $router
82
     */
83
    public static function registerRoutes(Router $router)
84
    {
85
        $routeName = 'admin.form.element.'.static::$route;
86
87
        if (! $router->has($routeName)) {
88
            $router->post('{adminModel}/'.static::$route.'/{field}/{id?}', [
89
                'as' => $routeName,
90
                'uses' => 'SleepingOwl\Admin\Http\Controllers\FormElementController@selectSearch',
91
            ]);
92
        }
93
    }
94
95
    /**
96
     * Getter of search url.
97
     * @return string
98
     */
99
    public function getSearchUrl()
100
    {
101
        return $this->search_url ? $this->search_url : route('admin.form.element.'.static::$route, [
102
            'adminModel' => AdminSection::getModel($this->model)->getAlias(),
103
            'field' => $this->getName(),
104
            'id' => $this->model->getKey(),
105
        ]);
106
    }
107
108
    /**
109
     * Search url for ajax.
110
     * @param $url
111
     * @return $this
112
     */
113
    public function setSearchUrl($url)
114
    {
115
        $this->search_url = $url;
116
117
        return $this;
118
    }
119
120
    /**
121
     * @return array
122
     */
123
    public function toArray()
124
    {
125
        $this->setLoadOptionsQueryPreparer($this->default_query_preparer);
126
127
        $this->setHtmlAttributes([
128
            'id' => $this->getId(),
129
            'class' => 'form-control js-data-ajax',
130
            'data-select-type' => 'single',
131
            //'model' => get_class($this->getModelForOptions()),
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
132
            //'field' => $this->getDisplay(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
133
            //'search' => $this->getSearch(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
134
            'search_url' => $this->getSearchUrl(),
135
            'data-min-symbols' => $this->getMinSymbols(),
136
        ]);
137
138
        if (count($this->getDataDependsArray())) {
139
            $depends = $this->getDataDependsArray();
140
            $depends = array_map(function ($el) {
141
                return strtr($el, ['.' => '__']);
142
            }, $depends);
143
            $depends = json_encode($depends);
144
145
            $this->setHtmlAttributes([
146
                'data-language' => $this->getLanguage(),
147
                'data-depends' => $depends,
148
                'data-url' => $this->getSearchUrl(),
149
                'class' => 'input-select input-select-dependent',
150
            ]);
151
        }
152
153
        return ['attributes' => $this->getHtmlAttributes()] + parent::toArray();
154
    }
155
}
156