TMultiple::setSize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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