Passed
Push — master ( 9ff117...796cdf )
by Hong
01:49
created

ConfigAwareTrait::setConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * Phoole (PHP7.2+)
5
 *
6
 * @category  Library
7
 * @package   Phoole\Config
8
 * @copyright Copyright (c) 2019 Hong Zhang
9
 */
10
declare(strict_types = 1);
11
12
namespace Phoole\Config;
13
14
/**
15
 * ConfigAwareTrait
16
 *
17
 * @package Phoole\Config
18
 */
19
trait ConfigAwareTrait
20
{
21
    /**
22
     * @var ConfigInterface
23
     */
24
    protected $config;
25
26
    /**
27
     * @param  ConfigInterface $config
28
     * @return $this
29
     */
30
    public function setConfig(ConfigInterface $config)
31
    {
32
        $this->config = $config;
33
        return $this;
34
    }
35
36
    /**
37
     * @return ConfigInterface
38
     * @throws \LogicException  if not set yet
39
     */
40
    public function getConfig(): ConfigInterface
41
    {
42
        if (is_null($this->config)) {
43
            throw new \LogicException("Config not set in " . get_class($this));
44
        }
45
        return $this->config;
46
    }
47
}