CollectionTrait::initElements()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 3
crap 2
1
<?php
2
3
4
namespace leandrogehlen\exporter\data;
5
6
use Yii;
7
8
/**
9
 * CollectionTrait implements the common methods for classes that contains collection properties
10
 *
11
 * @author Leandro Guindani Gehlen <[email protected]>
12
 */
13
trait CollectionTrait
14
{
15
    /**
16
     * @param array $collection collection configuration. Each array element represents
17
     * the configuration for one particular element.
18
     * @param string $class the element class name
19
     * @param array $config name-value pairs that will be used to initialize the object properties
20
     * @throws \yii\base\InvalidConfigException
21
     */
22 8
    protected function initElements(&$collection, $class, $config = [])
23
    {
24 8
        foreach ($collection as $i => $element) {
25 8
            $element = array_merge($config, $element);
26 8
            $element = Yii::createObject(array_merge([
27
                'class' => $class
28 8
            ], $element));
29
30 8
            $collection[$i] = $element;
31 8
        }
32 8
    }
33
}
34