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

LoopHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
c 0
b 0
f 0
dl 0
loc 29
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A autoStart() 0 3 1
A get() 0 9 2
A attach() 0 3 1
A setSignalHandlers() 0 4 1
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