ContainerAwareTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
dl 0
loc 28
rs 10
c 1
b 0
f 1
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 4 1
A getContainer() 0 6 2
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Di
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types=1);
11
12
namespace Phoole\Di;
13
14
use Psr\Container\ContainerInterface;
15
use Phoole\Di\Exception\LogicException;
16
17
/**
18
 * ContainerAwareTrait
19
 *
20
 * @package   Phoole\Di
21
 * @interface ContainerAwareInterface
22
 */
23
trait ContainerAwareTrait
24
{
25
    /**
26
     * @var ContainerInterface
27
     */
28
    protected $container;
29
30
    /**
31
     * Inject the container
32
     *
33
     * @param  ContainerInterface $container
34
     * @return $this
35
     */
36
    public function setContainer(ContainerInterface $container)
37
    {
38
        $this->container = $container;
39
        return $this;
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45
    public function getContainer(): ContainerInterface
46
    {
47
        if (is_null($this->container)) {
48
            throw new LogicException("Container not set in " . get_class($this));
49
        }
50
        return $this->container;
51
    }
52
}