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

RendersOptionsTrait::renderSelection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 0
dl 0
loc 11
ccs 0
cts 6
cp 0
crap 6
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace WebTheory\Saveyour\Concerns;
4
5
use WebTheory\Saveyour\Contracts\OptionsProviderInterface;
6
use WebTheory\Saveyour\Elements\Option;
7
8
trait RendersOptionsTrait
9
{
10
    use IsSelectionFieldTrait;
11
12
    /**
13
     * @var OptionsProviderInterface
14
     */
15
    protected $selectionProvider;
16
17
    /**
18
     * Get the value of selectionProvider
19
     *
20
     * @return OptionsProviderInterface
21
     */
22
    public function getSelectionProvider(): OptionsProviderInterface
23
    {
24
        return $this->selectionProvider;
25
    }
26
27
    /**
28
     * Set the value of selectionProvider
29
     *
30
     * @param OptionsProviderInterface $selectionProvider
31
     *
32
     * @return self
33
     */
34
    public function setSelectionProvider(OptionsProviderInterface $selectionProvider)
35
    {
36
        $this->selectionProvider = $selectionProvider;
37
38
        return $this;
39
    }
40
41
    /**
42
     *
43
     */
44
    protected function defineSelectionText($selection)
45
    {
46
        return $this->selectionProvider->defineSelectionText($selection);
47
    }
48
49
    /**
50
     *
51
     */
52
    protected function renderSelection(): string
53
    {
54
        $html = '';
55
56
        foreach ($this->getSelectionData() as $selection) {
57
            $selected = $this->isSelectionSelected($this->defineSelectionValue($selection));
0 ignored issues
show
Bug introduced by
It seems like isSelectionSelected() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

57
            /** @scrutinizer ignore-call */ 
58
            $selected = $this->isSelectionSelected($this->defineSelectionValue($selection));
Loading history...
58
59
            $html .= $this->createOption($selection)->setSelected($selected);
60
        }
61
62
        return $html;
63
    }
64
65
    /**
66
     *
67
     */
68
    protected function createOption($selection): Option
69
    {
70
        return new Option(
71
            $this->defineSelectionText($selection),
72
            $this->defineSelectionValue($selection)
73
        );
74
    }
75
}
76