ContextBehavior   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 10
c 1
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A context() 0 9 2
1
<?php
2
/**
3
 * @link https://github.com/lav45/yii2-settings
4
 * @copyright Copyright (c) 2016 LAV45
5
 * @author Aleksey Loban <[email protected]>
6
 * @license http://opensource.org/licenses/BSD-3-Clause
7
 */
8
9
namespace lav45\settings\behaviors;
10
11
use yii\base\Behavior;
12
13
/**
14
 * Class ContextBehavior
15
 * @package lav45\settings\behaviors
16
 *
17
 * @property \lav45\settings\Settings $owner
18
 */
19
class ContextBehavior extends Behavior
20
{
21
    /**
22
     * @var array
23
     */
24
    private $_models = [];
25
26 1
    public function context($data)
27
    {
28 1
        $key = md5(serialize($data));
29 1
        if (!isset($this->_models[$key])) {
30 1
            $settings = clone $this->owner;
31 1
            $settings->keyPrefix = $key;
32 1
            $this->_models[$key] = $settings;
33
        }
34 1
        return $this->_models[$key];
35
    }
36
}