Completed
Push — master ( 831b77...b56796 )
by Antonio
02:41
created

ClassMapHelper::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 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\Helper;
13
14
/**
15
 * ModelMapHelper.php.
16
 *
17
 * Date: 3/12/16
18
 * Time: 18:10
19
 *
20
 * @author Antonio Ramirez <[email protected]>
21
 */
22
class ClassMapHelper
23
{
24
    protected $map = [];
25
26
    /**
27
     * ModelClassMapHelper constructor.
28
     *
29
     * @param array $map
30
     */
31 10
    public function __construct($map = [])
32
    {
33 10
        $this->map = $map;
34 10
    }
35
36
    /**
37
     * @param $key
38
     * @param $class
39
     */
40
    public function set($key, $class)
41
    {
42
        $this->map[$key] = $class;
43
    }
44
45
    /**
46
     * @param $key
47
     *
48
     * @throws \Exception
49
     * @return mixed
50
     *
51
     */
52 10
    public function get($key)
53
    {
54 10
        if (array_key_exists($key, $this->map)) {
55 10
            return $this->map[$key];
56
        }
57
        throw new \Exception('Unknown model map key: ' . $key);
58
    }
59
}
60