Completed
Pull Request — master (#2447)
by jxlwqq
02:26
created

Radio::checked()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 10
loc 10
rs 9.9332
c 0
b 0
f 0
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 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...
46
    {
47
        if ($checked instanceof Arrayable) {
48
            $checked = $checked->toArray();
49
        }
50
51
        $this->checked = (array) $checked;
52
53
        return $this;
54
    }
55
56
57
    /**
58
     * Draw inline radios.
59
     *
60
     * @return $this
61
     */
62
    public function inline()
63
    {
64
        $this->inline = true;
65
66
        return $this;
67
    }
68
69
    /**
70
     * Draw stacked radios.
71
     *
72
     * @return $this
73
     */
74
    public function stacked()
75
    {
76
        $this->inline = false;
77
78
        return $this;
79
    }
80
81
    /**
82
     * Set options.
83
     *
84
     * @param array|callable|string $values
85
     *
86
     * @return $this
87
     */
88
    public function values($values)
89
    {
90
        return $this->options($values);
91
    }
92
93
    /**
94
     * {@inheritdoc}
95
     */
96
    public function render()
97
    {
98
        $this->script = "$('{$this->getElementClassSelector()}').iCheck({radioClass:'iradio_minimal-blue'});";
99
100
        $this->addVariables(['options' => $this->options, 'checked' => $this->checked, 'inline' => $this->inline]);
101
102
        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 102 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
103
    }
104
}
105