ContainerAwareTrait   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 1

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 35
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 6 1
A getContainer() 0 8 2
1
<?php declare(strict_types=1);
2
3
namespace League\Container;
4
5
use League\Container\Exception\ContainerException;
6
use Psr\Container\ContainerInterface;
7
8
trait ContainerAwareTrait
9
{
10
    /**
11
     * @var \Psr\Container\ContainerInterface
12
     */
13
    protected $container;
14
15
    /**
16
     * Set a container.
17
     *
18 66
     * @param \Psr\Container\ContainerInterface $container
19
     *
20 66
     * @return self
21
     */
22 66
    public function setContainer(ContainerInterface $container)
23
    {
24
        $this->container = $container;
25
26
        return $this;
27
    }
28
29
    /**
30 18
     * Get the container.
31
     *
32 18
     * @return \League\Container\ContainerInterface
33
     */
34
    public function getContainer(): ContainerInterface
35
    {
36
        if ($this->container instanceof ContainerInterface) {
37
            return $this->container;
38
        }
39
40
        throw new ContainerException('No container implementation has been set.');
41
    }
42
}
43