BaseCollection   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 3
A toArray() 0 9 2
getType() 0 1 ?
1
<?php
2
3
namespace GFG\DTOContext\DataWrapper;
4
5
abstract class BaseCollection extends \ArrayObject implements DataWrapperInterface
6
{
7
8
    /**
9
     * @param array $collection
10
     *
11
     * If not items of this collection already, it creates it!
12
     */
13 2
    public function __construct(array $collection = array())
14
    {
15 2
        $type = $this->getType();
16
17 2
        foreach ($collection as &$item) {
18 1
            if (!is_object($item)) {
19 1
                $item = new $type($item);
20 1
            }
21 2
        }
22
23 2
        parent::__construct($collection);
24 2
    }
25
26
    /**
27
     * @return array
28
     */
29 1
    public function toArray()
30
    {
31 1
        $return = [];
32 1
        foreach ($this as $key => $value) {
33 1
            $return[$key] = $value->toArray();
34 1
        }
35
36 1
        return $return;
37
    }
38
39
    /**
40
     * @return string Must return the class of this collection items
41
     */
42
    abstract protected function getType();
43
}
44