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

DriverSetup   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 31
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A enableInitialization() 0 4 1
A setup() 0 8 3
A enableLinker() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
namespace AlecRabbit\Spinner\Core;
7
8
use AlecRabbit\Spinner\Core\Contract\IDriver;
9
use AlecRabbit\Spinner\Core\Contract\IDriverLinker;
10
use AlecRabbit\Spinner\Core\Contract\IDriverSetup;
11
12
final class DriverSetup implements IDriverSetup
13
{
14
    private bool $initializationEnabled = false;
15
    private bool $linkerEnabled = false;
16
17
    public function __construct(
18
        protected IDriverLinker $linker,
19
    ) {
20
    }
21
22
    public function setup(IDriver $driver): void
23
    {
24
        if ($this->initializationEnabled) {
25
            $driver->initialize();
26
        }
27
28
        if ($this->linkerEnabled) {
29
            $this->linker->link($driver);
30
        }
31
    }
32
33
    public function enableInitialization(bool $enable): IDriverSetup
34
    {
35
        $this->initializationEnabled = $enable;
36
        return $this;
37
    }
38
39
    public function enableLinker(bool $enable): IDriverSetup
40
    {
41
        $this->linkerEnabled = $enable;
42
        return $this;
43
    }
44
}
45