ContainerAwareTrait::setContainer()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
cc 2
nc 2
nop 1
crap 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
    /**
13
     * @var ?ContainerInterface
14
     */
15
    protected $container;
16
17 63
    public function getContainer(): ?ContainerInterface
18
    {
19 63
        return $this->container;
20
    }
21
22 6
    public function setContainer(ContainerInterface $container): ContainerAwareInterface
23
    {
24 6
        $this->container = $container;
25
26 6
        if ($this instanceof ContainerAwareInterface) {
27 3
            return $this;
28
        }
29
30 3
        throw new RuntimeException(sprintf(
31 3
            'Trait (%s) must be consumed by an instance of (%s)',
32 3
            __TRAIT__,
33 3
            ContainerAwareInterface::class
34
        ));
35
    }
36
}
37