RadioGroup   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 86
ccs 0
cts 27
cp 0
rs 10
c 0
b 0
f 0
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createSelectionRadio() 0 3 1
A getSelectionProvider() 0 3 1
A renderHtmlMarkup() 0 22 3
A setIsInline() 0 5 1
A setSelectionProvider() 0 5 1
A isInline() 0 3 1
1
<?php
2
3
namespace WebTheory\Saveyour\Field\Type;
4
5
use WebTheory\Saveyour\Contracts\Field\FormFieldInterface;
6
use WebTheory\Saveyour\Contracts\Field\Selection\RadioGroupSelectionInterface;
7
use WebTheory\Saveyour\Field\Abstracts\SingleValueSelectionTrait;
8
use WebTheory\Saveyour\Field\Type\Abstracts\AbstractCompositeSelectionField;
9
10
class RadioGroup extends AbstractCompositeSelectionField implements FormFieldInterface
11
{
12
    use SingleValueSelectionTrait;
13
14
    protected bool $isInline = true;
15
16
    /**
17
     * @var RadioGroupSelectionInterface
18
     */
19
    protected $selectionProvider;
20
21
    /**
22
     * Get the value of isInline
23
     *
24
     * @return bool
25
     */
26
    public function isInline(): bool
27
    {
28
        return $this->isInline;
29
    }
30
31
    /**
32
     * Set the value of isInline
33
     *
34
     * @param bool $isInline
35
     *
36
     * @return $this
37
     */
38
    public function setIsInline(bool $isInline): RadioGroup
39
    {
40
        $this->isInline = $isInline;
41
42
        return $this;
43
    }
44
45
    /**
46
     * Get the value of selectionProvider
47
     *
48
     * @return RadioGroupSelectionInterface
49
     */
50
    public function getSelectionProvider(): RadioGroupSelectionInterface
51
    {
52
        return $this->selectionProvider;
53
    }
54
55
    /**
56
     * Set the value of selectionProvider
57
     *
58
     * @param RadioGroupSelectionInterface $selectionProvider
59
     *
60
     * @return $this
61
     */
62
    public function setSelectionProvider(RadioGroupSelectionInterface $selectionProvider): RadioGroup
63
    {
64
        $this->selectionProvider = $selectionProvider;
65
66
        return $this;
67
    }
68
69
    protected function renderHtmlMarkup(): string
70
    {
71
        $html = '';
72
73
        foreach ($this->getSelectionData() as $selection) {
74
            $id = $this->defineSelectionId($selection);
75
            $value = $this->defineSelectionValue($selection);
76
77
            $radio = $this->createSelectionRadio($selection)
78
                ->setChecked($this->isSelectionSelected($value))
79
                ->setDisabled($this->disabled)
80
                ->setName($this->name)
81
                ->setValue($value)
82
                ->setId($id);
83
84
            $label = $this->createSelectionLabel($selection)->setFor($id);
85
86
            $html .= $radio . $label;
87
            $html .= $this->isInline ? ' ' : '<br>';
88
        }
89
90
        return $html;
91
    }
92
93
    protected function createSelectionRadio($selection): Radio
0 ignored issues
show
Unused Code introduced by
The parameter $selection is not used and could be removed. ( Ignorable by Annotation )

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

93
    protected function createSelectionRadio(/** @scrutinizer ignore-unused */ $selection): Radio

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
94
    {
95
        return new Radio();
96
    }
97
}
98