ContainerAwareTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 46
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getDi() 0 4 1
A make() 0 4 1
A getAuth() 0 4 1
A getClassMap() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the 2amigos/yii2-usuario project.
5
 *
6
 * (c) 2amigOS! <http://2amigos.us/>
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 */
11
12
namespace Da\User\Traits;
13
14
use Da\User\Helper\AuthHelper;
15
use Da\User\Helper\ClassMapHelper;
16
use Yii;
17
use yii\base\InvalidConfigException;
18
use yii\di\Container;
19
20
/**
21
 * @property-read Container $di
22
 * @property-ready Da\User\Helper\AuthHelper $auth
23
 * @property-ready Da\User\Helper\ClassMapHelper $classMap
24
 */
25
trait ContainerAwareTrait
26
{
27
    /**
28
     * @return Container
29
     */
30 15
    public function getDi()
31
    {
32 15
        return Yii::$container;
33
    }
34
35
    /**
36
     * Gets a class from the container.
37
     *
38
     * @param string $class  he class name or an alias name (e.g. `foo`) that was previously registered via [[set()]]
39
     *                       or [[setSingleton()]]
40
     * @param array  $params constructor parameters
41
     * @param array  $config attributes
42
     *
43
     * @throws InvalidConfigException
44
     * @return object
45
     */
46 15
    public function make($class, $params = [], $config = [])
47
    {
48 15
        return $this->getDi()->get($class, $params, $config);
49
    }
50
51
    /**
52
     * @throws InvalidConfigException
53
     * @return \Da\User\Helper\AuthHelper|object
54
     *
55
     */
56 2
    public function getAuth()
57
    {
58 2
        return $this->getDi()->get(AuthHelper::class);
59
    }
60
61
    /**
62
     * @throws InvalidConfigException
63
     * @return \Da\User\Helper\ClassMapHelper|object
64
     *
65
     */
66 11
    public function getClassMap()
67
    {
68 11
        return $this->getDi()->get(ClassMapHelper::class);
69
    }
70
}
71