Radio   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 36
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A renderInput() 0 13 2
A set() 0 7 1
1
<?php
2
3
namespace kalanis\kw_tree_controls\Controls;
4
5
6
use kalanis\kw_forms\Controls;
7
use kalanis\kw_forms\Controls\RadioSet;
8
9
10
/**
11
 * Class Radio
12
 * @package kalanis\kw_tree_controls\Controls
13
 * Radio with simplified label
14
 */
15
class Radio extends Controls\Radio
16
{
17
    private static int $uniqid = 0;
18
19
    protected string $templateLabel = '';
20
    protected string $templateInput = '<label><input type="radio" value="%1$s"%2$s /> %3$s</label>';
21
22
    /**
23
     * @param string $alias
24
     * @param string|int|float|bool|null $value
25
     * @param string $label
26
     * @param string|int|float|bool|null $checked
27
     * @return $this
28
     */
29 2
    public function set(string $alias, $value = null, string $label = '', $checked = ''): parent
30
    {
31 2
        $this->setEntry($alias, $value, $label);
32 2
        $this->setChecked($checked);
33 2
        $this->setAttribute('id', sprintf('%s_%s', $this->getKey(), self::$uniqid));
34 2
        self::$uniqid++;
35 2
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type kalanis\kw_tree_controls\Controls\Radio which is incompatible with the type-hinted return parent.
Loading history...
36
    }
37
38 2
    public function renderInput($attributes = null): string
39
    {
40 2
        $this->fillParent();
41 2
        $this->addAttributes($attributes);
42 2
        if (!($this->parent instanceof RadioSet)) {
43 2
            $this->setAttribute('name', $this->getKey());
44
        }
45 2
        return $this->wrapIt(sprintf(
46 2
            $this->templateInput,
47 2
            $this->escaped(strval($this->getOriginalValue())),
48 2
            $this->renderAttributes(),
49 2
            $this->escaped(strval($this->getLabel()))
50 2
        ), $this->wrappersInput);
51
    }
52
}
53