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

RadioStyle::setDisplaysExtra()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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