Completed
Push — master ( cd483f...7f59e2 )
by Song
19s
created

Radio   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 98
Duplicated Lines 18.37 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 18
loc 98
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 10 10 2
A checked() 0 11 3
A inline() 0 6 1
A stacked() 0 6 1
A values() 0 4 1
A render() 8 8 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 Encore\Admin\Form\Field;
4
5
use Encore\Admin\Form\Field;
6
use Illuminate\Contracts\Support\Arrayable;
7
8
class Radio extends Field
9
{
10
    protected $inline = true;
11
12
    protected static $css = [
13
        '/vendor/laravel-admin/AdminLTE/plugins/iCheck/all.css',
14
    ];
15
16
    protected static $js = [
17
        'vendor/laravel-admin/AdminLTE/plugins/iCheck/icheck.min.js',
18
    ];
19
20
    /**
21
     * Set options.
22
     *
23
     * @param array|callable|string $options
24
     *
25
     * @return $this
26
     */
27 View Code Duplication
    public function options($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...
28
    {
29
        if ($options instanceof Arrayable) {
30
            $options = $options->toArray();
31
        }
32
33
        $this->options = (array) $options;
34
35
        return $this;
36
    }
37
38
    /**
39
     * Set checked.
40
     *
41
     * @param array|callable|string $checked
42
     *
43
     * @return $this
44
     */
45
    public function checked($checked = [])
46
    {
47
        if ($checked instanceof Arrayable) {
48
            $checked = $checked->toArray();
49
        }
50
51
        // input radio checked should be unique
52
        $this->checked = is_array($checked) ? (array) end($checked) : (array) $checked;
53
54
        return $this;
55
    }
56
57
58
    /**
59
     * Draw inline radios.
60
     *
61
     * @return $this
62
     */
63
    public function inline()
64
    {
65
        $this->inline = true;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Draw stacked radios.
72
     *
73
     * @return $this
74
     */
75
    public function stacked()
76
    {
77
        $this->inline = false;
78
79
        return $this;
80
    }
81
82
    /**
83
     * Set options.
84
     *
85
     * @param array|callable|string $values
86
     *
87
     * @return $this
88
     */
89
    public function values($values)
90
    {
91
        return $this->options($values);
92
    }
93
94
    /**
95
     * {@inheritdoc}
96
     */
97 View Code Duplication
    public function render()
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...
98
    {
99
        $this->script = "$('{$this->getElementClassSelector()}').iCheck({radioClass:'iradio_minimal-blue'});";
100
101
        $this->addVariables(['options' => $this->options, 'checked' => $this->checked, 'inline' => $this->inline]);
102
103
        return parent::render();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::render(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 103 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
104
    }
105
}
106