ContainerAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

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
     * @param \Psr\Container\ContainerInterface $container
19
     *
20
     * @return self
21
     */
22 114
    public function setContainer(ContainerInterface $container) : ContainerAwareInterface
23
    {
24 114
        $this->container = $container;
25
26 114
        return $this;
27
    }
28
29
    /**
30
     * Get the container.
31
     *
32
     * @return \Psr\Container\ContainerInterface
33
     */
34 99
    public function getContainer() : ContainerInterface
35
    {
36 99
        if ($this->container instanceof ContainerInterface) {
37 87
            return $this->container;
38
        }
39
40 15
        throw new ContainerException('No container implementation has been set.');
41
    }
42
}
43