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

Checkbox::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 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]);
87
88
        return parent::render()->with('inline', $this->inline);
0 ignored issues
show
Bug introduced by
The method with does only exist in Illuminate\View\View, but not in Illuminate\Contracts\View\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
89
    }
90
}
91