Passed
Push — master ( d4a0a9...a5fa1a )
by Alec
02:38 queued 13s
created

ADefaults::getSpinnerCharPattern()

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
nc 2
nop 0
dl 0
loc 7
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
0 ignored issues
show
Coding Style introduced by
Header blocks must be separated by a single blank line
Loading history...
4
// 20.06.22
5
namespace AlecRabbit\Spinner\Config\Defaults\A;
6
7
use AlecRabbit\Spinner\Config\Defaults\Contract\IClasses;
8
use AlecRabbit\Spinner\Config\Defaults\Contract\IDefaults;
9
use AlecRabbit\Spinner\Config\Defaults\Contract\ITerminal;
10
use AlecRabbit\Spinner\Config\Defaults\Mixin\DefaultConst;
11
use AlecRabbit\Spinner\Core\Contract\IFrame;
12
use AlecRabbit\Spinner\Core\Frame;
0 ignored issues
show
Bug introduced by
The type AlecRabbit\Spinner\Core\Frame was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use AlecRabbit\Spinner\Core\Loop\Contract\ILoopProbe;
14
use AlecRabbit\Spinner\Core\Loop\ReactLoopProbe;
15
use AlecRabbit\Spinner\Core\Loop\RevoltLoopProbe;
16
use AlecRabbit\Spinner\Core\Terminal\Contract\ITerminalProbe;
17
use AlecRabbit\Spinner\Core\Terminal\SymfonyTerminalProbe;
18
use AlecRabbit\Spinner\Helper\Asserter;
19
20
use const AlecRabbit\Spinner\CSI;
21
use const AlecRabbit\Spinner\RESET;
22
23
abstract class ADefaults implements IDefaults
24
{
25
    use DefaultConst;
26
27
    protected static int $millisecondsInterval;
28
    protected static float|int $shutdownDelay;
29
    protected static float|int $shutdownMaxDelay;
30
    protected static bool $isModeSynchronous;
31
    protected static bool $hideCursor;
32
    protected static string $messageOnFinalize;
33
    protected static string $messageOnExit;
34
    protected static string $messageOnInterrupt;
35
    protected static string $percentNumberFormat;
36
    protected static bool $createInitialized;
37
    protected static array $colorSupportLevels;
38
    protected static ?array $defaultStylePattern = null;
39
    protected static ?array $defaultCharPattern = null;
40
    protected static ?array $mainStylePattern = null;
41
    protected static ?array $mainCharPattern = null;
42
    protected static ?IFrame $mainLeadingSpacer = null;
43
    protected static ?IFrame $mainTrailingSpacer = null;
44
    protected static ?IFrame $defaultLeadingSpacer = null;
45
    protected static ?IFrame $defaultTrailingSpacer = null;
46
    protected static IClasses $classes;
47
    protected static ITerminal $terminal;
48
    protected static bool $autoStart;
49
    protected static bool $attachSignalHandlers;
50
    /**
51
     * @var resource
52
     */
53
    protected static $outputStream;
54
    protected static iterable $loopProbes;
55
    protected static iterable $terminalProbes;
56
    private static ?IDefaults $instance = null; // private, singleton
57
58
59
    private function __construct()
60
    {
61
        $this->reset();
62
    }
63
64
    public function reset(): void
65
    {
66
        self::$outputStream = self::defaultOutputStream();
67
        self::$loopProbes = self::defaultLoopProbes();
68
        self::$terminalProbes = self::defaultTerminalProbes();
69
        self::$classes = self::getClassesInstance();
70
        self::$terminal = self::getTerminalInstance();
71
72
        self::$shutdownDelay = self::SHUTDOWN_DELAY;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...efaults::SHUTDOWN_DELAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
73
        self::$shutdownMaxDelay = self::SHUTDOWN_MAX_DELAY;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...lts::SHUTDOWN_MAX_DELAY was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
74
        self::$messageOnFinalize = self::MESSAGE_ON_FINALIZE;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...ts::MESSAGE_ON_FINALIZE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
75
        self::$messageOnExit = self::MESSAGE_ON_EXIT;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...faults::MESSAGE_ON_EXIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
76
        self::$messageOnInterrupt = self::MESSAGE_ON_INTERRUPT;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...s::MESSAGE_ON_INTERRUPT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
77
        self::$hideCursor = self::TERMINAL_HIDE_CURSOR;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...s::TERMINAL_HIDE_CURSOR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
78
        self::$colorSupportLevels = self::TERMINAL_COLOR_SUPPORT_LEVELS;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...AL_COLOR_SUPPORT_LEVELS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
79
        self::$isModeSynchronous = self::SPINNER_MODE_IS_SYNCHRONOUS;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...NER_MODE_IS_SYNCHRONOUS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
80
        self::$createInitialized = self::SPINNER_CREATE_INITIALIZED;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...NNER_CREATE_INITIALIZED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
81
        self::$percentNumberFormat = self::PERCENT_NUMBER_FORMAT;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...::PERCENT_NUMBER_FORMAT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
82
        self::$millisecondsInterval = self::INTERVAL_MS;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...\ADefaults::INTERVAL_MS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
83
        self::$autoStart = self::AUTO_START;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...A\ADefaults::AUTO_START was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
84
        self::$attachSignalHandlers = self::ATTACH_SIGNAL_HANDLERS;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Confi...:ATTACH_SIGNAL_HANDLERS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
85
86
        self::$mainStylePattern = null;
87
        self::$mainCharPattern = null;
88
        self::$mainLeadingSpacer = null;
89
        self::$mainTrailingSpacer = null;
90
91
        self::$defaultStylePattern = [];
92
        self::$defaultCharPattern = [];
93
        self::$defaultLeadingSpacer = Frame::createEmpty();
94
        self::$defaultTrailingSpacer = Frame::createSpace();
95
    }
96
97
    /**
98
     * @return resource
99
     */
100
    protected static function defaultOutputStream()
101
    {
102
        return STDERR;
103
    }
104
105
    protected static function defaultLoopProbes(): iterable
106
    {
107
        // @codeCoverageIgnoreStart
108
        yield from [
109
            RevoltLoopProbe::class,
110
            ReactLoopProbe::class,
111
        ];
112
        // @codeCoverageIgnoreEnd
113
    }
114
115
    protected static function defaultTerminalProbes(): iterable
116
    {
117
        // @codeCoverageIgnoreStart
118
        yield from [
119
            SymfonyTerminalProbe::class,
120
        ];
121
        // @codeCoverageIgnoreEnd
122
    }
123
124
    protected static function getClassesInstance(): AClasses
125
    {
126
        return AClasses::getInstance();
127
    }
128
129
    final public static function getInstance(): self
130
    {
131
        if (null === self::$instance) {
132
            self::$instance =
133
                new class() extends ADefaults {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after class keyword; 0 found
Loading history...
134
                };
135
        }
136
        return self::$instance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::instance could return the type AlecRabbit\Spinner\Confi...ults\Contract\IDefaults which includes types incompatible with the type-hinted return AlecRabbit\Spinner\Config\Defaults\A\ADefaults. Consider adding an additional type-check to rule them out.
Loading history...
137
    }
138
139
    protected static function getTerminalInstance(): ITerminal
140
    {
141
        return ATerminal::getInstance(self::$terminalProbes);
142
    }
143
144
    public function getClasses(): IClasses
145
    {
146
        return self::$classes;
147
    }
148
149
    /** @inheritdoc */
150
    public function getOutputStream()
151
    {
152
        return self::$outputStream;
153
    }
154
155
    /** @inheritdoc */
156
    public function setOutputStream($stream): static
157
    {
158
        Asserter::assertStream($stream);
159
        self::$outputStream = $stream;
160
        return $this;
161
    }
162
163
    public function getIntervalMilliseconds(): int
164
    {
165
        return self::$millisecondsInterval;
166
    }
167
168
    public function setIntervalMilliseconds(int $defaultInterval): static
169
    {
170
        self::$millisecondsInterval = $defaultInterval;
171
        return $this;
172
    }
173
174
    public function getShutdownDelay(): float|int
175
    {
176
        return self::$shutdownDelay;
177
    }
178
179
    public function setShutdownDelay(float|int $shutdownDelay): static
180
    {
181
        self::$shutdownDelay = $shutdownDelay;
182
        return $this;
183
    }
184
185
    public function isModeSynchronous(): bool
186
    {
187
        return self::$isModeSynchronous;
188
    }
189
190
    public function setModeAsSynchronous(bool $isModeSynchronous): static
191
    {
192
        self::$isModeSynchronous = $isModeSynchronous;
193
        return $this;
194
    }
195
196
    public function isHideCursor(): bool
197
    {
198
        return self::$hideCursor;
199
    }
200
201
    public function setHideCursor(bool $hideCursor): static
202
    {
203
        self::$hideCursor = $hideCursor;
204
        return $this;
205
    }
206
207
    public function getDefaultCharPattern(): array
208
    {
209
        return self::$defaultCharPattern;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::defaultCharPattern could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
210
    }
211
212
    public function setDefaultCharPattern(array $char): static
213
    {
214
        self::$defaultCharPattern = $char;
215
        return $this;
216
    }
217
218
    public function getDefaultStylePattern(): array
219
    {
220
        return self::$defaultStylePattern;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::defaultStylePattern could return the type null which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
221
    }
222
223
    public function setDefaultStylePattern(array $style): static
224
    {
225
        self::$defaultStylePattern = $style;
226
        return $this;
227
    }
228
229
    public function getFinalMessage(): string
230
    {
231
        return self::$messageOnFinalize;
232
    }
233
234
    public function setFinalMessage(string $finalMessage): static
235
    {
236
        self::$messageOnFinalize = $finalMessage;
237
        return $this;
238
    }
239
240
    public function getMessageOnExit(): string
241
    {
242
        return self::$messageOnExit;
243
    }
244
245
    public function setMessageOnExit(string $messageOnExit): static
246
    {
247
        self::$messageOnExit = $messageOnExit;
248
        return $this;
249
    }
250
251
    public function getInterruptMessage(): string
252
    {
253
        return self::$messageOnInterrupt;
254
    }
255
256
    public function setInterruptMessage(string $interruptMessage): static
257
    {
258
        self::$messageOnInterrupt = $interruptMessage;
259
        return $this;
260
    }
261
262
    public function getMaxShutdownDelay(): float|int
263
    {
264
        return self::$shutdownMaxDelay;
265
    }
266
267
    public function setMaxShutdownDelay(float|int $maxShutdownDelay): static
268
    {
269
        self::$shutdownMaxDelay = $maxShutdownDelay;
270
        return $this;
271
    }
272
273
    public function getColorSupportLevels(): array
274
    {
275
        return self::$colorSupportLevels;
276
    }
277
278
    /** @inheritdoc */
279
    public function setColorSupportLevels(array $colorSupportLevels): static
280
    {
281
        Asserter::assertColorSupportLevels($colorSupportLevels);
282
        self::$colorSupportLevels = $colorSupportLevels;
283
        return $this;
284
    }
285
286
287
    public function getPercentNumberFormat(): string
288
    {
289
        return self::$percentNumberFormat;
290
    }
291
292
    public function setPercentNumberFormat(string $percentNumberFormat): static
293
    {
294
        self::$percentNumberFormat = $percentNumberFormat;
295
        return $this;
296
    }
297
298
    public function getSpinnerStylePattern(): array
299
    {
300
        // TODO (2022-10-14 16:03) [Alec Rabbit]: change return type to ? [e68824d4-3908-49e4-9daf-73777963d37b]
301
        if (null === self::$mainStylePattern) {
302
            self::$mainStylePattern = [
303
                CSI . '38;5;196m%s' . RESET,
304
                CSI . '38;5;202m%s' . RESET,
305
                CSI . '38;5;208m%s' . RESET,
306
                CSI . '38;5;214m%s' . RESET,
307
                CSI . '38;5;220m%s' . RESET,
308
                CSI . '38;5;226m%s' . RESET,
309
                CSI . '38;5;190m%s' . RESET,
310
                CSI . '38;5;154m%s' . RESET,
311
                CSI . '38;5;118m%s' . RESET,
312
                CSI . '38;5;82m%s' . RESET,
313
                CSI . '38;5;46m%s' . RESET,
314
                CSI . '38;5;47m%s' . RESET,
315
                CSI . '38;5;48m%s' . RESET,
316
                CSI . '38;5;49m%s' . RESET,
317
                CSI . '38;5;50m%s' . RESET,
318
                CSI . '38;5;51m%s' . RESET,
319
                CSI . '38;5;45m%s' . RESET,
320
                CSI . '38;5;39m%s' . RESET,
321
                CSI . '38;5;33m%s' . RESET,
322
                CSI . '38;5;27m%s' . RESET,
323
                CSI . '38;5;56m%s' . RESET,
324
                CSI . '38;5;57m%s' . RESET,
325
                CSI . '38;5;93m%s' . RESET,
326
                CSI . '38;5;129m%s' . RESET,
327
                CSI . '38;5;165m%s' . RESET,
328
                CSI . '38;5;201m%s' . RESET,
329
                CSI . '38;5;200m%s' . RESET,
330
                CSI . '38;5;199m%s' . RESET,
331
                CSI . '38;5;198m%s' . RESET,
332
                CSI . '38;5;197m%s' . RESET,
333
            ];
334
        }
335
        return self::$mainStylePattern;
336
    }
337
338
    public function setSpinnerStylePattern(array $spinnerStylePattern): static
339
    {
340
        self::$mainStylePattern = $spinnerStylePattern;
341
        return $this;
342
    }
343
344
    public function getSpinnerCharPattern(): array
345
    {
346
        // TODO (2022-10-14 16:03) [Alec Rabbit]: change return type to ? [f96f5d87-f9f9-46dc-a45b-8eecc2aba711]
347
        if (null === self::$mainCharPattern) {
348
            self::$mainCharPattern = ['⠏', '⠛', '⠹', '⢸', '⣰', '⣤', '⣆', '⡇'];
349
        }
350
        return self::$mainCharPattern;
351
    }
352
353
    public function setSpinnerCharPattern(array $spinnerCharPattern): static
354
    {
355
        self::$mainCharPattern = $spinnerCharPattern;
356
        return $this;
357
    }
358
359
    public function getMainLeadingSpacer(): IFrame
360
    {
361
        return
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::mainLeading...f::defaultLeadingSpacer could return the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\Contract\IFrame. Consider adding an additional type-check to rule them out.
Loading history...
362
            self::$mainLeadingSpacer ?? self::$defaultLeadingSpacer;
363
    }
364
365
    public function setMainLeadingSpacer(IFrame $mainLeadingSpacer): static
366
    {
367
        self::$mainLeadingSpacer = $mainLeadingSpacer;
368
        return $this;
369
    }
370
371
    public function getMainTrailingSpacer(): IFrame
372
    {
373
        return
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::mainTrailin...::defaultTrailingSpacer could return the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\Contract\IFrame. Consider adding an additional type-check to rule them out.
Loading history...
374
            self::$mainTrailingSpacer ?? self::$defaultTrailingSpacer;
375
    }
376
377
    public function setMainTrailingSpacer(IFrame $mainTrailingSpacer): static
378
    {
379
        self::$mainTrailingSpacer = $mainTrailingSpacer;
380
        return $this;
381
    }
382
383
    public function isCreateInitialized(): bool
384
    {
385
        return self::$createInitialized;
386
    }
387
388
    public function setCreateInitialized(bool $createInitialized): static
389
    {
390
        self::$createInitialized = $createInitialized;
391
        return $this;
392
    }
393
394
    public function getDefaultLeadingSpacer(): IFrame
395
    {
396
        return self::$defaultLeadingSpacer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::defaultLeadingSpacer could return the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\Contract\IFrame. Consider adding an additional type-check to rule them out.
Loading history...
397
    }
398
399
    public function getDefaultTrailingSpacer(): IFrame
400
    {
401
        return self::$defaultTrailingSpacer;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::defaultTrailingSpacer could return the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\Contract\IFrame. Consider adding an additional type-check to rule them out.
Loading history...
402
    }
403
404
    public function isAutoStartEnabled(): bool
405
    {
406
        return self::$autoStart;
407
    }
408
409
    public function setAutoStart(bool $autoStart): static
410
    {
411
        self::$autoStart = $autoStart;
412
        return $this;
413
    }
414
415
    public function areSignalHandlersEnabled(): bool
416
    {
417
        return self::$attachSignalHandlers;
418
    }
419
420
    public function setAttachSignalHandlers(bool $attachSignalHandlers): static
421
    {
422
        self::$attachSignalHandlers = $attachSignalHandlers;
423
        return $this;
424
    }
425
426
    public function getLoopProbeClasses(): iterable
427
    {
428
        return self::$loopProbes;
429
    }
430
431
    public function getTerminalProbeClasses(): iterable
432
    {
433
        return self::$terminalProbes;
434
    }
435
436
    /** @inheritdoc */
437
    public function setTerminalProbeClasses(iterable $terminalProbes): static
438
    {
439
        foreach ($terminalProbes as $probe) {
440
            Asserter::isSubClass($probe, ITerminalProbe::class, __METHOD__);
441
        }
442
        self::$terminalProbes = $terminalProbes;
443
        return $this;
444
    }
445
446
    /** @inheritdoc */
447
    public function setLoopProbeClasses(iterable $loopProbes): static
448
    {
449
        foreach ($loopProbes as $probe) {
450
            Asserter::isSubClass($probe, ILoopProbe::class, __METHOD__);
451
        }
452
        self::$loopProbes = $loopProbes;
453
        return $this;
454
    }
455
456
    public function getTerminal(): ITerminal
457
    {
458
        return self::$terminal;
459
    }
460
}
461