Passed
Push — master ( 823aee...b9b37f )
by Alec
13:15 queued 12s
created

ALoopSettings::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
// 20.03.23
5
namespace AlecRabbit\Spinner\Core\Defaults\A;
6
7
use AlecRabbit\Spinner\Contract\AutoStart;
8
use AlecRabbit\Spinner\Contract\SignalHandlers;
9
use AlecRabbit\Spinner\Core\Defaults\Contract\IDefaults;
10
use AlecRabbit\Spinner\Core\Defaults\Contract\ILoopSettings;
11
use AlecRabbit\Spinner\Core\Defaults\Mixin\DefaultsConst;
12
13
abstract class ALoopSettings extends ADefaultsChild implements ILoopSettings
14
{
15
    use DefaultsConst;
16
17
    protected static AutoStart $autoStartOption;
18
    protected static SignalHandlers $signalHandlersOption;
19
20
    private static ?ILoopSettings $objInstance = null;
21
22
    final protected function __construct(IDefaults $parent)
23
    {
24
        parent::__construct($parent);
25
        $this->reset();
26
    }
27
28
    protected function reset(): void
29
    {
30
        static::$autoStartOption = static::AUTO_START_OPTION;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Core\...ings::AUTO_START_OPTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
        static::$signalHandlersOption = static::SIGNAL_HANDLERS_OPTION;
0 ignored issues
show
Bug introduced by
The constant AlecRabbit\Spinner\Core\...:SIGNAL_HANDLERS_OPTION was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
32
    }
33
34
    final public static function getInstance(IDefaults $parent): ILoopSettings
35
    {
36
        if (null === self::$objInstance) {
37
            self::$objInstance =
38
                new class ($parent) extends ALoopSettings {
39
                };
40
        }
41
        return self::$objInstance;
42
    }
43
44
    public function getAutoStartOption(): AutoStart
45
    {
46
        return static::$autoStartOption;
47
    }
48
49
    public function getSignalHandlersOption(): SignalHandlers
50
    {
51
        return static::$signalHandlersOption;
52
    }
53
54
    public function overrideAutoStartOption(AutoStart $autoStartOption): ILoopSettings
55
    {
56
        static::$autoStartOption = $autoStartOption;
57
        return $this;
58
    }
59
60
    public function overrideSignalHandlersOption(SignalHandlers $signalHandlersOption): ILoopSettings
61
    {
62
        static::$signalHandlersOption = $signalHandlersOption;
63
        return $this;
64
    }
65
}