Completed
Pull Request — master (#203)
by
unknown
01:54
created

CheckableStyle   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 22
c 1
b 1
f 0
dl 0
loc 39
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromArray() 0 8 1
A toArray() 0 7 1
A __construct() 0 8 1
1
<?php
2
3
namespace PhpSchool\CliMenu\Style;
4
5
class CheckableStyle implements ItemStyleInterface
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