Checkbox::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 6
ccs 5
cts 5
cp 1
crap 1
rs 10
c 2
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_forms\Controls;
4
5
6
use kalanis\kw_forms\Interfaces\IOriginalValue;
7
8
9
/**
10
 * Class Checkbox
11
 * @package kalanis\kw_forms\Controls
12
 * Form element for checkboxes
13
 */
14
class Checkbox extends AControl implements IOriginalValue
15
{
16
    use TChecked;
17
18
    private static int $uniqid = 0;
19
    protected string $templateInput = '<input type="checkbox" value="%1$s"%2$s />';
20
21
    /**
22
     * @param string $alias
23
     * @param string|int|float|null $value
24
     * @param string $label
25
     * @return $this
26
     */
27 5
    public function set(string $alias, $value = null, string $label = ''): self
28
    {
29 5
        $this->setEntry($alias, $value, $label);
30 5
        $this->setAttribute('id', sprintf('%s_%s', $this->getKey(), self::$uniqid));
31 5
        self::$uniqid++;
32 5
        return $this;
33
    }
34
35 1
    public function getOriginalValue()
36
    {
37 1
        return $this->originalValue;
38
    }
39
40 5
    protected function fillTemplate(): string
41
    {
42 5
        return '%2$s %1$s';
43
    }
44
}
45