Passed
Pull Request — master (#205)
by Aydin
02:04
created

CheckboxStyle::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
namespace PhpSchool\CliMenu\Style;
4
5
class CheckboxStyle
6
{
7
    use ItemStyleTrait;
8
9
    protected const DEFAULT_STYLES = [
10
        'markerOn'      => '[✔] ',
11
        'markerOff'     => '[ ] ',
12
        'itemExtra'     => '✔',
13
        'displaysExtra' => false,
14
    ];
15
16
    public function __construct()
17
    {
18
        $this->setMarkerOn(self::DEFAULT_STYLES['markerOn']);
19
        $this->setMarkerOff(self::DEFAULT_STYLES['markerOff']);
20
        $this->setItemExtra(self::DEFAULT_STYLES['itemExtra']);
21
        $this->setDisplaysExtra(self::DEFAULT_STYLES['displaysExtra']);
22
23
        $this->custom = false;
24
    }
25
26
    public function toArray() : array
27
    {
28
        return [
29
            'markerOn'      => $this->markerOn,
30
            'markerOff'     => $this->markerOff,
31
            'itemExtra'     => $this->itemExtra,
32
            'displaysExtra' => $this->displaysExtra,
33
        ];
34
    }
35
36
    public function fromArray(array $style) : self
37
    {
38
        $this->markerOn      = $style['markerOn'] ?? $this->markerOn;
39
        $this->markerOff     = $style['markerOff'] ?? $this->markerOff;
40
        $this->itemExtra     = $style['itemExtra'] ?? $this->itemExtra;
41
        $this->displaysExtra = $style['displaysExtra'] ?? $this->displaysExtra;
42
43
        return $this;
44
    }
45
}
46