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

Select   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 65
rs 10
c 1
b 0
f 0
wmc 6
lcom 1
cbo 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptions() 0 4 1
A getOptions() 0 4 1
A isAutoSubmit() 0 4 1
A setAutoSubmit() 0 4 1
A render() 0 7 2
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