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   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 79
Duplicated Lines 39.24 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 24.32%

Importance

Changes 0
Metric Value
dl 31
loc 79
c 0
b 0
f 0
ccs 9
cts 37
cp 0.2432
rs 10
wmc 7
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 12 12 1
A registerRoutes() 11 11 2
A setSearchUrl() 0 6 1
A getSearchUrl() 8 8 2
A toArray() 0 14 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\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