Completed
Push — master ( 696114...b35b16 )
by Phil
05:53 queued 02:05
created

ContainerAwareTrait::getContainer()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 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 102
    public function setContainer(ContainerInterface $container): ContainerAwareInterface
23
    {
24 102
        $this->container = $container;
25
26 102
        return $this;
27
    }
28
29
    /**
30
     * Get the container.
31
     *
32
     * @return \Psr\Container\ContainerInterface
33
     */
34 102
    public function getContainer(): ContainerInterface
35
    {
36 102
        if ($this->container instanceof ContainerInterface) {
37 90
            return $this->container;
38
        }
39
40 15
        throw new ContainerException('No container implementation has been set.');
41
    }
42
}
43