MagicStoreTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 18
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A _store() 0 4 2
1
<?php
2
/*
3
 *  @copyright (c) 2019 Mendel <[email protected]>
4
 *  @license see license.txt
5
 */
6
7
namespace drycart\di;
8
9
/**
10
 * Magic for store dependency
11
 * 
12
 * @author mendel
13
 */
14
trait MagicStoreTrait
15
{
16
    /**
17
     * Used at constructor. Store all constructor parameters as object variables
18
     * If exist optional parameter $keys - store only this variables (for example if
19
     * call parent constructor which same this methods call)
20
     * CALL ONLY FROM CONSTRUCTOR
21
     * 
22
     * $this->_store(get_defined_vars());
23
     * 
24
     * @param array $data
25
     * @param array $keys
26
     * @return void
27
     */
28
    protected function _store(array $data, ?array $keys = null) : void
29
    {
30
        foreach ($keys ?? array_keys($data) as $key) {
31
            $this->$key = $data[$key] ?? null;
32
        }
33
    }    
34
}
35