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

LoopHelper::setSignalHandlers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
// 17.02.23
5
6
namespace AlecRabbit\Spinner\Asynchronous\Loop;
7
8
use AlecRabbit\Spinner\Asynchronous\Factory\LoopFactory;
9
use AlecRabbit\Spinner\Core\Contract\ILoopAdapter;
10
use AlecRabbit\Spinner\Core\Contract\ILoopHelper;
11
use AlecRabbit\Spinner\Core\Contract\ISpinner;
12
13
final class LoopHelper implements ILoopHelper
14
{
15
    private static ?ILoopAdapter $loopInstance = null;
16
17
    public static function attach(ISpinner $spinner): void
18
    {
19
        self::get()->attach($spinner);
20
    }
21
22
    public static function get(): ILoopAdapter
23
    {
24
        if (self::$loopInstance instanceof ILoopAdapter) {
25
            return self::$loopInstance;
26
        }
27
28
        self::$loopInstance = LoopFactory::create();
29
30
        return self::$loopInstance;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::loopInstance returns the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\Contract\ILoopAdapter.
Loading history...
31
    }
32
33
    public static function setSignalHandlers(ISpinner $spinner, ?iterable $handlers = null): void
34
    {
35
        $handlers ??= self::get()->createSignalHandlers($spinner);
36
        self::get()->setSignalHandlers($handlers);
37
    }
38
39
    public static function autoStart(): void
40
    {
41
        self::get()->autoStart();
42
    }
43
}
44