Completed
Push — master ( c362d7...55e77b )
by Adam
03:14
created

Select::setAutoSubmit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid\Filters;
4
5
class Select extends Filter
6
{
7
    /**
8
     * @var array
9
     */
10
    protected $options = [];
11
12
    /**
13
     * @var string
14
     */
15
    protected $emptyValue = '--';
16
17
    /**
18
     * @var string
19
     */
20
    protected $operator = FilterOperator::OPERATOR_EQ;
21
22
    /**
23
     * @var bool
24
     */
25
    protected $autoSubmit = true;
26
27
    /**
28
     * @param array $options
29
     */
30
    public function setOptions(array $options)
31
    {
32
        $this->options = ['' => $this->emptyValue] + $options;
33
    }
34
35
    /**
36
     * @return array
37
     */
38
    public function getOptions()
39
    {
40
        return $this->options;
41
    }
42
43
    /**
44
     * @return boolean
45
     */
46
    public function isAutoSubmit(): bool
47
    {
48
        return $this->autoSubmit;
49
    }
50
51
    /**
52
     * @param boolean $flag
53
     */
54
    public function setAutoSubmit(bool $flag)
55
    {
56
        $this->autoSubmit = $flag;
57
    }
58
59
    /**
60
     * @return \Illuminate\Support\HtmlString
61
     */
62
    public function render()
63
    {
64
        return $this->getFormBuilder()->select($this->getName(), $this->options, $this->getInput(), [
0 ignored issues
show
Bug introduced by
It seems like $this->getInput() targeting Boduch\Grid\Filters\Filter::getInput() can also be of type array; however, Collective\Html\FormBuilder::select() does only seem to accept string|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
65
            'class' => 'form-control input-sm',
66
            'onchange' => $this->autoSubmit ? 'this.form.submit()' : ''
67
        ]);
68
    }
69
}
70