Radio   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 52
ccs 22
cts 22
cp 1
rs 10
c 2
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A fillTemplate() 0 3 1
A set() 0 6 1
A getOriginalValue() 0 3 1
A renderLabel() 0 4 1
A fillParent() 0 5 2
A renderInput() 0 8 2
1
<?php
2
3
namespace kalanis\kw_forms\Controls;
4
5
6
use kalanis\kw_forms\Interfaces\IOriginalValue;
7
8
9
/**
10
 * Class Radio
11
 * @package kalanis\kw_forms\Controls
12
 * Render input for selecting by radio checkbox
13
 */
14
class Radio extends AControl implements IOriginalValue
15
{
16
    use TChecked;
17
18
    protected string $templateInput = '<input type="radio" value="%1$s"%2$s />';
19
20
    /**3
21
     * @param string $alias
22
     * @param string|int|float|null $value
23
     * @param string $label
24
     * @param string $checked
25
     * @return $this
26
     */
27 2
    public function set(string $alias, $value = null, string $label = '', $checked = ''): self
28
    {
29 2
        $this->setEntry($alias, $value, $label);
30 2
        $this->setChecked($checked);
31 2
        $this->setAttribute('id', $this->getKey());
32 2
        return $this;
33
    }
34
35 2
    protected function fillTemplate(): string
36
    {
37 2
        return '%2$s %1$s';
38
    }
39
40 2
    public function getOriginalValue()
41
    {
42 2
        return $this->originalValue;
43
    }
44
45 2
    public function renderInput($attributes = null): string
46
    {
47 2
        $this->fillParent();
48 2
        $this->addAttributes($attributes);
49 2
        if (!($this->parent instanceof RadioSet)) {
50 1
            $this->setAttribute('name', $this->getKey());
51
        }
52 2
        return $this->wrapIt(sprintf($this->templateInput, $this->escaped(strval($this->getOriginalValue())), $this->renderAttributes(), $this->renderChildren()), $this->wrappersInput);
53
    }
54
55 2
    public function renderLabel($attributes = []): string
56
    {
57 2
        $this->fillParent();
58 2
        return parent::renderLabel($attributes);
59
    }
60
61 2
    protected function fillParent(): void
62
    {
63 2
        if ($this->parent instanceof RadioSet) {
64 1
            $this->setAttribute('name', strval($this->parent->getAttribute('name')));
0 ignored issues
show
Bug introduced by
The method getAttribute() does not exist on kalanis\kw_templates\Interfaces\IHtmlElement. Did you maybe mean getAttributes()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            $this->setAttribute('name', strval($this->parent->/** @scrutinizer ignore-call */ getAttribute('name')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug introduced by
The method getAttribute() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
            $this->setAttribute('name', strval($this->parent->/** @scrutinizer ignore-call */ getAttribute('name')));

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
65 1
            $this->setAttribute('id', $this->parent->getKey() . '_' . strval($this->getOriginalValue()));
66
        }
67 2
    }
68
}
69