Passed
Push — master ( ce4c49...96250d )
by Alec
02:39
created

Settings::getStyles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Spinner\Core;
4
5
use AlecRabbit\Spinner\Contracts\SettingsInterface;
6
7
/**
8
 * Class Settings
9
 *
10
 * @psalm-suppress PropertyNotSetInConstructor
11
 */
12
class Settings implements SettingsInterface
13
{
14
    /** @var float */
15
    protected $interval;
16
    /** @var int */
17
    protected $erasingShift;
18
    /** @var string */
19
    protected $message;
20
    /** @var string */
21
    protected $prefix;
22
    /** @var string */
23
    protected $suffix;
24
    /** @var string */
25
    protected $inlinePaddingStr;
26
    /** @var array */
27
    protected $symbols;
28
    /** @var array */
29
    protected $styles;
30
31
    /**
32
     * Settings constructor.
33
     */
34 10
    public function __construct()
35
    {
36 10
        $this->defaults();
37 10
    }
38
39 10
    protected function defaults(): Settings
40
    {
41
        return
42
            $this
43 10
                ->setSuffix(null)
44 10
                ->setSymbols(null)
45 10
                ->setStyles(null)
46 10
                ->setMessage(null)
47 10
                ->setPrefix(null)
48 10
                ->setInterval(null)
49 10
                ->setErasingShift(null)
50 10
                ->setInlinePaddingStr(null);
51
    }
52
53
    /**
54
     * @return float
55
     */
56 10
    public function getInterval(): float
57
    {
58 10
        return $this->interval;
59
    }
60
61
    /**
62
     * @param null|float $interval
63
     * @return Settings
64
     */
65 10
    public function setInterval(?float $interval): Settings
66
    {
67 10
        $this->interval = $interval ?? SettingsInterface::DEFAULT_INTERVAL;
68 10
        return $this;
69
    }
70
71
    /**
72
     * @return int
73
     */
74 10
    public function getErasingShift(): int
75
    {
76 10
        return $this->erasingShift;
77
    }
78
79
    /**
80
     * @param null|int $erasingShift
81
     * @return Settings
82
     */
83 10
    public function setErasingShift(?int $erasingShift): Settings
84
    {
85 10
        $this->erasingShift = $erasingShift ?? SettingsInterface::DEFAULT_ERASING_SHIFT;
86 10
        return $this;
87
    }
88
89
    /**
90
     * @return string
91
     */
92 10
    public function getMessage(): string
93
    {
94 10
        return $this->message;
95
    }
96
97
    /**
98
     * @param null|string $message
99
     * @return Settings
100
     */
101 10
    public function setMessage(?string $message): Settings
102
    {
103 10
        $this->message = $message ?? SettingsInterface::EMPTY;
104 10
        if (SettingsInterface::EMPTY === $this->message) {
105 10
            $this->setSuffix(SettingsInterface::EMPTY);
106
        } else {
107 9
            $this->setSuffix(SettingsInterface::DEFAULT_SUFFIX);
108
        }
109 10
        return $this;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 10
    public function getPrefix(): string
116
    {
117 10
        return $this->prefix;
118
    }
119
120
    /**
121
     * @param null|string $prefix
122
     * @return Settings
123
     */
124 10
    public function setPrefix(?string $prefix): Settings
125
    {
126 10
        $this->prefix = $prefix ?? SettingsInterface::ONE_SPACE_SYMBOL;
127 10
        return $this;
128
    }
129
130
    /**
131
     * @return string
132
     */
133 10
    public function getSuffix(): string
134
    {
135 10
        return $this->suffix;
136
    }
137
138
    /**
139
     * @param null|string $suffix
140
     * @return Settings
141
     */
142 10
    public function setSuffix(?string $suffix): Settings
143
    {
144 10
        $this->suffix = $suffix ?? SettingsInterface::DEFAULT_SUFFIX;
145 10
        return $this;
146
    }
147
148
    /**
149
     * @return string
150
     */
151 10
    public function getInlinePaddingStr(): string
152
    {
153 10
        return $this->inlinePaddingStr;
154
    }
155
156
    /**
157
     * @param null|string $inlinePaddingStr
158
     * @return Settings
159
     */
160 10
    public function setInlinePaddingStr(?string $inlinePaddingStr): Settings
161
    {
162 10
        $this->inlinePaddingStr = $inlinePaddingStr ?? SettingsInterface::EMPTY;
163 10
        return $this;
164
    }
165
166
    /**
167
     * @return array
168
     */
169 10
    public function getSymbols(): array
170
    {
171 10
        return $this->symbols;
172
    }
173
174
    /**
175
     * @param null|array $symbols
176
     * @return Settings
177
     */
178 10
    public function setSymbols(?array $symbols): Settings
179
    {
180 10
        $this->symbols = $symbols ?? static::DEFAULT_SYMBOLS;
181 10
        return $this;
182
    }
183
184
    /**
185
     * @return array
186
     */
187 10
    public function getStyles(): array
188
    {
189 10
        return $this->styles;
190
    }
191
192
    /**
193
     * @param null|array $styles
194
     * @return Settings
195
     */
196 10
    public function setStyles(?array $styles): Settings
197
    {
198 10
        $this->styles = array_merge(static::DEFAULT_STYLES, $styles ?? []);
199 10
        return $this;
200
    }
201
}
202