TMultiple   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 43
ccs 12
cts 12
cp 1
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getMultiple() 0 3 1
A setMultiple() 0 9 4
A setSize() 0 3 1
1
<?php
2
3
namespace kalanis\kw_forms\Controls;
4
5
6
/**
7
 * Class TMultiple
8
 * @package kalanis\kw_forms\Controls
9
 * Render input for selecting multiple inputs by select
10
 */
11
trait TMultiple
12
{
13
    /**
14
     * Set if select has multiple values to get
15
     * @param string $value
16
     */
17 1
    public function setMultiple($value): void
18
    {
19 1
        if (!empty($value) && ('none' !== strval($value))) {
20 1
            $this->setAttribute('multiple', 'multiple');
21 1
            if (!$this->getAttribute('size')) {
22 1
                $this->setSize(count($this->children));
23
            }
24
        } else {
25 1
            $this->removeAttribute('multiple');
26
        }
27 1
    }
28
29
    /**
30
     * Set displayed size
31
     * 1 or less for drop menu
32
     * 2 or more for list
33
     * @param int $value
34
     */
35 2
    public function setSize(int $value): void
36
    {
37 2
        $this->setAttribute('size', strval($value));
38 2
    }
39
40
    /**
41
     * Get if select could get multiple values
42
     * @return bool
43
     */
44 2
    public function getMultiple(): bool
45
    {
46 2
        return ('multiple' == $this->getAttribute('multiple'));
47
    }
48
49
    abstract public function setAttribute(string $name, string $value): void;
50
51
    abstract public function removeAttribute(string $name): void;
52
53
    abstract public function getAttribute(string $name): ?string;
54
}
55