MagicStoreTrait::_store()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 4
rs 10
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