Passed
Push — master ( 957a79...8bbf21 )
by SignpostMarv
06:44
created

AttachDaftFramework   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 37
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A DetachDaftFramework() 0 9 2
A AttachDaftFramework() 0 9 2
A GetDaftFramework() 0 3 1
A CheckIfUsingFrameworkInstance() 0 3 1
1
<?php
2
/**
3
* @author SignpostMarv
4
*/
5
declare(strict_types=1);
6
7
namespace SignpostMarv\DaftFramework;
8
9
use BadMethodCallException;
10
11
trait AttachDaftFramework
12
{
13
    /**
14
    * @var Framework|null
15
    */
16
    protected $daftFrameworkInstance;
17
18 4
    public function AttachDaftFramework(Framework $framework) : void
19
    {
20 4
        if ($this->daftFrameworkInstance instanceof Framework) {
21 2
            throw new BadMethodCallException(
22 2
                'Framework must not be attached if a framework is already attached!'
23
            );
24
        }
25
26 4
        $this->daftFrameworkInstance = $framework;
27 4
    }
28
29 4
    public function DetachDaftFramework() : ? Framework
30
    {
31 4
        $out = $this->daftFrameworkInstance;
32
33 4
        if ($out instanceof Framework) {
34 2
            $this->daftFrameworkInstance = null;
35
        }
36
37 4
        return $out;
38
    }
39
40 4
    public function GetDaftFramework() : ? Framework
41
    {
42 4
        return $this->daftFrameworkInstance;
43
    }
44
45 2
    public function CheckIfUsingFrameworkInstance(Framework ...$instances) : bool
46
    {
47 2
        return in_array($this->daftFrameworkInstance, $instances, true);
48
    }
49
}
50