Completed
Pull Request — master (#139)
by
unknown
10:24
created

Children   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 8
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 45
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 3
A add() 0 10 4
A getAll() 0 4 1
1
<?php
2
3
namespace Yandex\Market\Content\Models;
4
5
use Yandex\Common\ObjectModel;
6
7
class Children extends ObjectModel
8
{
9
    /**
10
     * Constructor
11
     *
12
     * @param array $data
13
     */
14
    public function __construct($data = array())
15
    {
16
        // fix children inheritance
17
        if (isset($data['models'])
18
            && count($data['models']) > 0)
19
            $data = $data['models'];
20
21
        parent::__construct($data);
22
    }
23
24
    /**
25
     * Add childModel to collection
26
     *
27
     * @param ModelChild|array $childModel
28
     *
29
     * @return Children
30
     */
31
    public function add($childModel)
32
    {
33
        if (is_array($childModel)) {
34
            $this->collection[] = new ModelChild($childModel);
35
        } elseif (is_object($childModel) && $childModel instanceof ModelChild) {
36
            $this->collection[] = $childModel;
37
        }
38
39
        return $this;
40
    }
41
42
    /**
43
     * Retrieve the collection property
44
     *
45
     * @return Children
46
     */
47
    public function getAll()
48
    {
49
        return $this->collection;
50
    }
51
}
52