Completed
Push — master ( 01c6de...4be10b )
by Song
12:49
created

Footer::disableSubmit()   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', 'continue_creating'];
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
     * Disable Creating Checkbox.
98
     *
99
     * @return $this
100
     */
101
    public function disableCreatingCheck()
102
    {
103
        array_delete($this->checkboxes, 'continue_creating');
104
105
        return $this;
106
    }
107
108
    /**
109
     * Setup scripts.
110
     */
111
    protected function setupScript()
112
    {
113
        $script = <<<'EOT'
114
$('.after-submit').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChecked', function () {
115
    $('.after-submit').not(this).iCheck('uncheck');
116
});
117
EOT;
118
119
        Admin::script($script);
120
    }
121
122
    /**
123
     * Render footer.
124
     *
125
     * @return string
126
     */
127
    public function render()
128
    {
129
        $this->setupScript();
130
131
        $data = [
132
            'buttons'      => $this->buttons,
133
            'checkboxes'   => $this->checkboxes,
134
            'width'        => $this->builder->getWidth(),
135
        ];
136
137
        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...
138
    }
139
}
140