Passed
Push — master ( a90def...5de986 )
by Chris
04:49
created

RadioGroup::isInline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Fields;
4
5
use WebTheory\Saveyour\Concerns\SingleValueSelectionTrait;
6
use WebTheory\Saveyour\Contracts\FormFieldInterface;
7
use WebTheory\Saveyour\Contracts\RadioGroupSelectionInterface;
8
9
class RadioGroup extends AbstractCompositeSelectionField implements FormFieldInterface
10
{
11
    use SingleValueSelectionTrait;
12
13
    /**
14
     * @var bool
15
     */
16
    protected $isInline = true;
17
18
    /**
19
     * @var RadioGroupSelectionInterface
20
     */
21
    protected $selectionProvider;
22
23
    /**
24
     * Get the value of isInline
25
     *
26
     * @return bool
27
     */
28
    public function isInline(): bool
29
    {
30
        return $this->isInline;
31
    }
32
33
    /**
34
     * Set the value of isInline
35
     *
36
     * @param bool $isInline
37
     *
38
     * @return self
39
     */
40
    public function setIsInline(bool $isInline)
41
    {
42
        $this->isInline = $isInline;
43
44
        return $this;
45
    }
46
47
    /**
48
     * Get the value of selectionProvider
49
     *
50
     * @return RadioGroupSelectionInterface
51
     */
52
    public function getSelectionProvider(): RadioGroupSelectionInterface
53
    {
54
        return $this->selectionProvider;
55
    }
56
57
    /**
58
     * Set the value of selectionProvider
59
     *
60
     * @param RadioGroupSelectionInterface $selectionProvider
61
     *
62
     * @return self
63
     */
64
    public function setSelectionProvider(RadioGroupSelectionInterface $selectionProvider)
65
    {
66
        $this->selectionProvider = $selectionProvider;
67
68
        return $this;
69
    }
70
71
    /**
72
     *
73
     */
74
    protected function renderHtmlMarkup(): string
75
    {
76
        $html = '';
77
78
        foreach ($this->getSelectionData() as $selection) {
79
            $id = $this->defineSelectionId($selection);
80
            $value = $this->defineSelectionValue($selection);
81
82
            $radio = $this->createSelectionRadio($selection)
83
                ->setChecked($this->isSelectionSelected($value))
84
                ->setName($this->name)
85
                ->setValue($value)
86
                ->setId($id);
87
88
            $label = $this->createSelectionLabel($selection)->setFor($id);
89
90
            $html .= $radio . $label;
91
            $html .= $this->isInline ? ' ' : '<br>';
92
        }
93
94
        return $html;
95
    }
96
97
    /**
98
     *
99
     */
100
    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

100
    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...
101
    {
102
        return new Radio();
103
    }
104
}
105