Passed
Push — master ( de3d61...be839c )
by Alec
13:42 queued 13s
created

LoopFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getLoopProbe() 0 3 1
A getLoop() 0 6 2
A createLoop() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AlecRabbit\Spinner\Core\Factory;
6
7
use AlecRabbit\Spinner\Core\Contract\Loop\Contract\ILoop;
8
use AlecRabbit\Spinner\Core\Contract\Loop\Contract\ILoopProbe;
9
use AlecRabbit\Spinner\Core\Factory\Contract\ILoopProbeFactory;
10
use AlecRabbit\Spinner\Core\Factory\Contract\ILoopFactory;
11
12
final class LoopFactory implements ILoopFactory
13
{
14
    private static ?ILoop $loop = null;
15
16
    public function __construct(
17
        protected ILoopProbeFactory $loopProbeFactory,
18
    ) {
19
    }
20
21
    public function getLoop(): ILoop
22
    {
23
        if (self::$loop === null) {
24
            self::$loop = $this->createLoop();
25
        }
26
        return self::$loop;
0 ignored issues
show
Bug Best Practice introduced by
The expression return self::loop could return the type null which is incompatible with the type-hinted return AlecRabbit\Spinner\Core\...act\Loop\Contract\ILoop. Consider adding an additional type-check to rule them out.
Loading history...
27
    }
28
29
    private function createLoop(): ILoop
30
    {
31
        return $this->getLoopProbe()->createLoop();
32
    }
33
34
    private function getLoopProbe(): ILoopProbe
35
    {
36
        return $this->loopProbeFactory->getProbe();
37
    }
38
}
39