ContainerAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 2
b 0
f 0
dl 0
loc 21
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getContainer() 0 3 1
A setContainer() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace League\Route;
6
7
use Psr\Container\ContainerInterface;
8
use RuntimeException;
9
10
trait ContainerAwareTrait
11
{
12
    protected ?ContainerInterface $container = null;
13
14 45
    public function getContainer(): ?ContainerInterface
15
    {
16 45
        return $this->container;
17
    }
18
19 6
    public function setContainer(ContainerInterface $container): ContainerAwareInterface
20
    {
21 6
        $this->container = $container;
22
23 6
        if ($this instanceof ContainerAwareInterface) {
24 3
            return $this;
25
        }
26
27 3
        throw new RuntimeException(sprintf(
28 3
            'Trait (%s) must be consumed by an instance of (%s)',
29 3
            __TRAIT__,
30 3
            ContainerAwareInterface::class
31 3
        ));
32
    }
33
}
34