Completed
Push — develop ( 467115...a39d71 )
by Adrien
17:43
created

SpgrContainer   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
dl 0
loc 75
ccs 14
cts 18
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setParent() 0 4 1
A getParent() 0 4 1
A addChild() 0 5 1
A getAllSpContainers() 0 14 3
A getChildren() 0 4 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer;
4
5
/**
6
 * Copyright (c) 2006 - 2016 PhpSpreadsheet.
7
 *
8
 * This library is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * This library is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with this library; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
21
 *
22
 * @category   PhpSpreadsheet
23
 *
24
 * @copyright  Copyright (c) 2006 - 2016 PhpSpreadsheet (https://github.com/PHPOffice/PhpSpreadsheet)
25
 * @license    http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt    LGPL
26
 */
27
class SpgrContainer
28
{
29
    /**
30
     * Parent Shape Group Container.
31
     *
32
     * @var \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer
33
     */
34
    private $parent;
35
36
    /**
37
     * Shape Container collection.
38
     *
39
     * @var array
40
     */
41
    private $children = [];
42
43
    /**
44
     * Set parent Shape Group Container.
45
     *
46
     * @param \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer $parent
47
     */
48
    public function setParent($parent)
49
    {
50
        $this->parent = $parent;
51
    }
52
53
    /**
54
     * Get the parent Shape Group Container if any.
55
     *
56
     * @return \PhpOffice\PhpSpreadsheet\Shared\Escher\DgContainer\SpgrContainer|null
57
     */
58 3
    public function getParent()
59
    {
60 3
        return $this->parent;
61
    }
62
63
    /**
64
     * Add a child. This will be either spgrContainer or spContainer.
65
     *
66
     * @param mixed $child
67
     */
68 10
    public function addChild($child)
69
    {
70 10
        $this->children[] = $child;
71 10
        $child->setParent($this);
72 10
    }
73
74
    /**
75
     * Get collection of Shape Containers.
76
     */
77 10
    public function getChildren()
78
    {
79 10
        return $this->children;
80
    }
81
82
    /**
83
     * Recursively get all spContainers within this spgrContainer.
84
     *
85
     * @return SpgrContainer\SpContainer[]
86
     */
87 3
    public function getAllSpContainers()
88
    {
89 3
        $allSpContainers = [];
90
91 3
        foreach ($this->children as $child) {
92 3
            if ($child instanceof self) {
93
                $allSpContainers = array_merge($allSpContainers, $child->getAllSpContainers());
94
            } else {
95 3
                $allSpContainers[] = $child;
96
            }
97
        }
98
99 3
        return $allSpContainers;
100
    }
101
}
102