Completed
Push — master ( 4eea1d...c89067 )
by Hong
04:28
created

ContainerAwareTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setContainer() 0 5 1
A getContainer() 0 7 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
16
/**
17
 * ContainerAwareTrait
18
 *
19
 * @package Phoole\Di
20
 */
21
trait ContainerAwareTrait
22
{
23
    /**
24
     * @var ContainerInterface
25
     */
26
    protected $container;
27
28
    /**
29
     * @param  ContainerInterface $container
30
     * @return $this
31
     */
32
    public function setContainer(ContainerInterface $container)
33
    {
34
        $this->container = $container;
35
        return $this;
36
    }
37
38
    /**
39
     * @return ContainerInterface
40
     * @throws \LogicException     if not set yet
41
     */
42
    public function getContainer(): ContainerInterface
43
    {
44
        if (is_null($this->container)) {
45
            throw new \LogicException("Container not set in " . get_class($this));
46
        }
47
        return $this->container;
48
    }
49
}