Completed
Push — master ( da5a0b...090289 )
by Aydin
18s queued 11s
created

CheckboxStyle::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace PhpSchool\CliMenu\Style;
4
5
class CheckboxStyle
6
{
7
    protected const DEFAULT_STYLES = [
8
        'markerOn'      => '[✔] ',
9
        'markerOff'     => '[ ] ',
10
        'itemExtra'     => '✔',
11
        'displaysExtra' => false,
12
    ];
13
14
    protected $markerOn = '';
15
16
    protected $markerOff = '';
17
18
    protected $itemExtra = '';
19
20
    protected $displaysExtra = false;
21
22
    protected $custom = false;
23
24
    public function __construct()
25
    {
26
        $this->markerOn      = self::DEFAULT_STYLES['markerOn'];
27
        $this->markerOff     = self::DEFAULT_STYLES['markerOff'];
28
        $this->itemExtra     = self::DEFAULT_STYLES['itemExtra'];
29
        $this->displaysExtra = self::DEFAULT_STYLES['displaysExtra'];
30
    }
31
32
    public function hasChangedFromDefaults() : bool
33
    {
34
        return $this->custom;
35
    }
36
37
    public function getMarker(bool $selected) : string
38
    {
39
        return $selected ? $this->markerOn : $this->markerOff;
40
    }
41
42
    public function getMarkerOn() : string
43
    {
44
        return $this->markerOn;
45
    }
46
47
    public function setMarkerOn(string $marker) : self
48
    {
49
        $this->custom = true;
50
51
        $this->markerOn = $marker;
52
53
        return $this;
54
    }
55
56
    public function getMarkerOff() : string
57
    {
58
        return $this->markerOff;
59
    }
60
61
    public function setMarkerOff(string $marker) : self
62
    {
63
        $this->custom = true;
64
65
        $this->markerOff = $marker;
66
67
        return $this;
68
    }
69
70
    public function getItemExtra() : string
71
    {
72
        return $this->itemExtra;
73
    }
74
75
    public function setItemExtra(string $itemExtra) : self
76
    {
77
        $this->custom = true;
78
79
        $this->itemExtra = $itemExtra;
80
81
        // if we customise item extra, it means we most likely want to display it
82
        $this->setDisplaysExtra(true);
83
84
        return $this;
85
    }
86
87
    public function getDisplaysExtra() : bool
88
    {
89
        return $this->displaysExtra;
90
    }
91
92
    public function setDisplaysExtra(bool $displaysExtra) : self
93
    {
94
        $this->custom = true;
95
96
        $this->displaysExtra = $displaysExtra;
97
98
        return $this;
99
    }
100
}
101