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

RendersOptionsTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
dl 0
loc 65
ccs 0
cts 17
cp 0
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSelectionProvider() 0 3 1
A setSelectionProvider() 0 5 1
A renderSelection() 0 11 2
A createOption() 0 5 1
A defineSelectionText() 0 3 1
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