Completed
Pull Request — master (#2447)
by jxlwqq
03:41
created

Checkbox   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 84
Duplicated Lines 33.33 %

Coupling/Cohesion

Components 2
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 1
dl 28
loc 84
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 10 10 2
A checked() 10 10 2
A inline() 0 6 1
A stacked() 0 6 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 Illuminate\Contracts\Support\Arrayable;
6
7
class Checkbox extends MultipleSelect
8
{
9
    protected $inline = true;
10
11
    protected static $css = [
12
        '/vendor/laravel-admin/AdminLTE/plugins/iCheck/all.css',
13
    ];
14
15
    protected static $js = [
16
        '/vendor/laravel-admin/AdminLTE/plugins/iCheck/icheck.min.js',
17
    ];
18
19
    /**
20
     * Set options.
21
     *
22
     * @param array|callable|string $options
23
     *
24
     * @return $this|mixed
25
     */
26 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...
27
    {
28
        if ($options instanceof Arrayable) {
29
            $options = $options->toArray();
30
        }
31
32
        $this->options = (array) $options;
33
34
        return $this;
35
    }
36
37
    /**
38
     * Set checked.
39
     *
40
     * @param array|callable|string $checked
41
     *
42
     * @return $this
43
     */
44 View Code Duplication
    public function checked($checked = [])
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...
45
    {
46
        if ($checked instanceof Arrayable) {
47
            $checked = $checked->toArray();
48
        }
49
50
        $this->checked = (array) $checked;
51
52
        return $this;
53
    }
54
55
    /**
56
     * Draw inline checkboxes.
57
     *
58
     * @return $this
59
     */
60
    public function inline()
61
    {
62
        $this->inline = true;
63
64
        return $this;
65
    }
66
67
    /**
68
     * Draw stacked checkboxes.
69
     *
70
     * @return $this
71
     */
72
    public function stacked()
73
    {
74
        $this->inline = false;
75
76
        return $this;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82 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...
83
    {
84
        $this->script = "$('{$this->getElementClassSelector()}').iCheck({checkboxClass:'icheckbox_minimal-blue'});";
85
86
        $this->addVariables(['checked' => $this->checked, 'inline' => $this->inline]);
87
88
        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 88 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
89
    }
90
}
91