TMultiple::setMultiple()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
nc 3
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 4
rs 10
c 1
b 0
f 0
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