Passed
Push — master ( 3c0766...793f0f )
by Chris
05:28
created

AbstractChecklist::createItemLabel()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
namespace WebTheory\Saveyour\Fields;
4
5
use WebTheory\Saveyour\Concerns\HasLabelsTrait;
6
use WebTheory\Saveyour\Concerns\IsSelectionFieldTrait;
7
use WebTheory\Saveyour\Contracts\FormFieldInterface;
8
use WebTheory\Saveyour\Elements\Label;
9
10
abstract class AbstractChecklist extends AbstractFormField implements FormFieldInterface
11
{
12
    use HasLabelsTrait;
13
    use IsSelectionFieldTrait;
14
15
    /**
16
     * Associative array of item definitions with the value as the key
17
     *
18
     * @var array
19
     */
20
    protected $items = [];
21
22
    /**
23
     * @var string[]
24
     */
25
    protected $value = [];
26
27
    /**
28
     * Get the value of items
29
     *
30
     * @return mixed
31
     */
32
    public function getItems()
33
    {
34
        return $this->items;
35
    }
36
37
    /**
38
     * Set the value of items
39
     *
40
     * @param mixed $items
41
     *
42
     * @return self
43
     */
44
    public function setItems($items)
45
    {
46
        $this->items = $items;
47
48
        return $this;
49
    }
50
51
    /**
52
     *
53
     */
54
    protected function getItemsToRender(): array
55
    {
56
        return $this->selectionProvider
57
            ? $this->selectionProvider->getSelection()
58
            : $this->items;
59
    }
60
    /**
61
     *
62
     */
63
    protected function isItemChecked(string $item): bool
64
    {
65
        return in_array($item, $this->value);
66
    }
67
68
    /**
69
     *
70
     */
71
    protected function createItemLabel(array $values): Label
72
    {
73
        return $this->createLabel($values['label'] ?? '', $this->labelOptions);
74
    }
75
}
76