Completed
Push — master ( 4730d9...235cc5 )
by Phil
02:29
created

ContainerAwareTrait::setLeagueContainer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 ContainerInterface
12
     */
13
    protected $container;
14
15
    /**
16
     * @var Container
17
     */
18
    protected $leagueContainer;
19
20
    /**
21
     * Set a container.
22
     *
23
     * @param ContainerInterface $container
24
     *
25
     * @return self
26
     */
27 9
    public function setContainer(ContainerInterface $container) : ContainerAwareInterface
28
    {
29 9
        $this->container = $container;
30
31 9
        return $this;
32
    }
33
34
    /**
35
     * Get the container.
36
     *
37
     * @return ContainerInterface
38
     */
39 6
    public function getContainer() : ContainerInterface
40
    {
41 6
        if ($this->container instanceof ContainerInterface) {
42 6
            return $this->container;
43
        }
44
45
        throw new ContainerException('No container implementation has been set.');
46
    }
47
48
    /**
49
     * Set a container.
50
     *
51
     * @param Container $container
52
     *
53
     * @return self
54
     */
55 111
    public function setLeagueContainer(Container $container) : ContainerAwareInterface
56
    {
57 111
        $this->container = $container;
58 111
        $this->leagueContainer = $container;
59
60 111
        return $this;
61
    }
62
63
    /**
64
     * Get the container.
65
     *
66
     * @return Container
67
     */
68 102
    public function getLeagueContainer() : Container
69
    {
70 102
        if ($this->leagueContainer instanceof Container) {
71 81
            return $this->leagueContainer;
72
        }
73
74 24
        throw new ContainerException('No container implementation has been set.');
75
    }
76
}
77