ClassMapHelper::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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