Options::setOptions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace kalanis\kw_table\form_kw\Fields;
4
5
6
use kalanis\kw_connect\core\Interfaces\IFilterFactory;
7
use kalanis\kw_connect\core\Interfaces\IFilterType;
8
9
10
/**
11
 * Class Options
12
 * @package kalanis\kw_table\form_kw\Fields
13
 * Contains empty value
14
 */
15
class Options extends AField
16
{
17
    /** @var string */
18
    protected string $emptyItem = '- all -';
19
    /** @var array<string, string|int|float> */
20
    protected array $options = [];
21
22
    /**
23
     * @param array<string, string|int|float> $options
24
     * @param array<string, string> $attributes
25
     */
26 2
    public function __construct(array $options = [], array $attributes = [])
27
    {
28 2
        $this->setOptions($options);
29 2
        parent::__construct($attributes);
30 2
    }
31
32 2
    public function getFilterAction(): string
33
    {
34 2
        return IFilterFactory::ACTION_EXACT;
35
    }
36
37
    /**
38
     * @param array<string, string|int|float> $options
39
     * @return $this
40
     */
41 2
    public function setOptions(array $options): self
42
    {
43 2
        $this->options = [IFilterType::EMPTY_FILTER => $this->emptyItem] + $options;
44 2
        return $this;
45
    }
46
47 1
    public function setEmptyItem(string $text): void
48
    {
49 1
        $this->emptyItem = $text;
50 1
    }
51
52 2
    public function add(): void
53
    {
54 2
        $this->getFormInstance()->addSelect($this->alias, '', null, $this->options, $this->attributes);
55 2
    }
56
}
57