CollectionTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A initElements() 0 11 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