Completed
Pull Request — master (#2327)
by
unknown
02:57
created

Footer::disableViewCheck()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form;
4
5
use Encore\Admin\Admin;
6
use Illuminate\Contracts\Support\Renderable;
7
8
class Footer implements Renderable
9
{
10
    /**
11
     * Footer view.
12
     *
13
     * @var string
14
     */
15
    protected $view = 'admin::form.footer';
16
17
    /**
18
     * Form builder instance.
19
     *
20
     * @var Builder
21
     */
22
    protected $builder;
23
24
    /**
25
     * Available buttons.
26
     *
27
     * @var array
28
     */
29
    protected $buttons = ['reset', 'submit'];
30
31
    /**
32
     * Available checkboxes.
33
     *
34
     * @var array
35
     */
36
    protected $checkboxes = ['view', 'continue_editing'];
37
38
    /**
39
     * Footer constructor.
40
     *
41
     * @param Builder $builder
42
     */
43
    public function __construct(Builder $builder)
44
    {
45
        $this->builder = $builder;
46
    }
47
48
    /**
49
     * Disable reset button.
50
     *
51
     * @return $this
52
     */
53
    public function disableReset()
54
    {
55
        array_delete($this->buttons, 'reset');
56
57
        return $this;
58
    }
59
60
    /**
61
     * Disable submit button.
62
     *
63
     * @return $this
64
     */
65
    public function disableSubmit()
66
    {
67
        array_delete($this->buttons, 'submit');
68
69
        return $this;
70
    }
71
72
    /**
73
     * Disable View Checkbox.
74
     *
75
     * @return $this
76
     */
77
    public function disableViewCheck()
78
    {
79
        array_delete($this->checkboxes, 'view');
80
81
        return $this;
82
    }
83
84
    /**
85
     * Disable Editing Checkbox.
86
     *
87
     * @return $this
88
     */
89
    public function disableEditingCheck()
90
    {
91
        array_delete($this->checkboxes, 'continue_editing');
92
93
        return $this;
94
    }
95
96
    /**
97
     * Setup scripts.
98
     */
99
    protected function setupScript()
100
    {
101
        $script = <<<'EOT'
102
$('.after-submit').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChecked', function () {
103
    $('.after-submit').not(this).iCheck('uncheck');
104
});
105
EOT;
106
107
        Admin::script($script);
108
    }
109
110
    /**
111
     * Render footer.
112
     *
113
     * @return string
114
     */
115
    public function render()
116
    {
117
        $this->setupScript();
118
119
        $data = [
120
            'buttons'   => $this->buttons,
121
            'checkboxes'   => $this->checkboxes,
122
            'width'     => $this->builder->getWidth(),
123
        ];
124
125
        return view($this->view, $data)->render();
0 ignored issues
show
Bug introduced by
The method render 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...
126
    }
127
}
128