TypeResolver::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
/**
3
 *
4
 * @author Mihkel Viilveer <[email protected]>
5
 * @date 25.08.2014
6
 */
7
8
namespace opus\elastic\spooler;
9
10
use yii\base\ErrorException;
11
12
/**
13
 * Class TypeResolver
14
 * This class resolves elasticsearch type configuration
15
 * If more types are needed into configuration then you can override path param
16
 * with yii container parameter setter
17
 *
18
 * @author Mihkel Viilveer <[email protected]>
19
 * @package opus\elastic
20
 */
21
class TypeResolver
22
{
23
    /**
24
     * Path to the types config file
25
     * @var string
26
     */
27
    public $path = '@vendor/opus-online/yii2-elastic/src/config/types';
28
29
    /**
30
     * Cached configuration
31
     * @var array
32
     */
33
    private $config = [];
34
35
    /**
36
     * Loads configuration
37
     */
38
    function __construct()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
39
    {
40
        if (empty($this->config)) {
41
            $this->config = require(\Yii::getAlias($this->path) . '.php');
42
        }
43
    }
44
45
    /**
46
     * @param $type
47
     * @throws \yii\base\ErrorException
48
     * @return
49
     */
50
    public function resolve($type)
51
    {
52
        if (!isset($this->config[$type])) {
53
            throw new ErrorException('Unknown type:' . $type );
54
        }
55
        return $this->config[$type];
56
    }
57
} 
58