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 — master ( b864c9...ed9166 )
by butschster
12:41
created

SelectAjax::getSearchUrl()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 8
loc 8
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
ccs 0
cts 6
cp 0
crap 6
rs 9.4285
1
<?php
2
3
namespace SleepingOwl\Admin\Form\Element;
4
5
use Illuminate\Routing\Router;
6
use Illuminate\Database\Eloquent\Model;
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
17
    /**
18
     * @param string $path
19
     * @param string|null $label
20
     * @param array|Model $options
21
     */
22 View Code Duplication
    public function __construct($path, $label = null, $options = [])
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, $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
     * @param $url
52
     */
53
    public function setSearchUrl($url)
54
    {
55
        $this->search_url = $url;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 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...
64
    {
65
        return $this->search_url ? $this->search_url : route('admin.form.element.'.static::$route, [
66
                'adminModel' => \AdminSection::getModel($this->model)->getAlias(),
67
                'field' => $this->getName(),
68
                'id' => $this->model->getKey(),
69
            ]);
70
    }
71
72
    /**
73
     * @return array
74
     */
75
    public function toArray()
76
    {
77
        $attributes = [
78
            'id'               => $this->getName(),
79
            'size'             => 2,
80
            'data-select-type' => 'single',
81
            'class'            => 'form-control js-data-ajax',
82
            'model'            => get_class($this->getModelForOptions()),
83
            'field'            => $this->getDisplay(),
84
            'search_url'       => $this->getSearchUrl(),
85
        ];
86
87
        return ['attributes' => $attributes] + parent::toArray();
88
    }
89
}
90