Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
16 / 16
CRAP
100.00% covered (success)
100.00%
45 / 45
Group
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
16 / 16
20
100.00% covered (success)
100.00%
45 / 45
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getShapeCollection
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 addShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getOffsetX
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 setOffsetX
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getOffsetY
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 setOffsetY
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getExtentX
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 getExtentY
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 setWidth
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setHeight
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 createRichTextShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 createLineShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 createChartShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 createDrawingShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 createTableShape
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
1<?php
2/**
3 * This file is part of PHPPresentation - A pure PHP library for reading and writing
4 * presentations documents.
5 *
6 * PHPPresentation is free software distributed under the terms of the GNU Lesser
7 * General Public License version 3 as published by the Free Software Foundation.
8 *
9 * For the full copyright and license information, please read the LICENSE
10 * file that was distributed with this source code. For the full list of
11 * contributors, visit https://github.com/PHPOffice/PHPPresentation/contributors.
12 *
13 * @see        https://github.com/PHPOffice/PHPPresentation
14 *
15 * @copyright   2009-2015 PHPPresentation contributors
16 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
17 */
18
19declare(strict_types=1);
20
21namespace PhpOffice\PhpPresentation\Shape;
22
23use ArrayObject;
24use PhpOffice\PhpPresentation\AbstractShape;
25use PhpOffice\PhpPresentation\GeometryCalculator;
26use PhpOffice\PhpPresentation\ShapeContainerInterface;
27
28class Group extends AbstractShape implements ShapeContainerInterface
29{
30    /**
31     * Collection of shapes.
32     *
33     * @var array<int, AbstractShape>|ArrayObject<int, AbstractShape>
34     */
35    private $shapeCollection;
36
37    /**
38     * Extent X.
39     *
40     * @var int
41     */
42    protected $extentX;
43
44    /**
45     * Extent Y.
46     *
47     * @var int
48     */
49    protected $extentY;
50
51    public function __construct()
52    {
53        parent::__construct();
54
55        // Shape collection
56        $this->shapeCollection = new ArrayObject();
57    }
58
59    /**
60     * Get collection of shapes.
61     *
62     * @return array<int, AbstractShape>|ArrayObject<int, AbstractShape>
63     */
64    public function getShapeCollection()
65    {
66        return $this->shapeCollection;
67    }
68
69    /**
70     * Add shape to slide.
71     *
72     * @return AbstractShape
73     */
74    public function addShape(AbstractShape $shape): AbstractShape
75    {
76        $shape->setContainer($this);
77
78        return $shape;
79    }
80
81    /**
82     * Get X Offset.
83     */
84    public function getOffsetX(): int
85    {
86        if (empty($this->offsetX)) {
87            $offsets = GeometryCalculator::calculateOffsets($this);
88            $this->offsetX = $offsets[GeometryCalculator::X];
89            $this->offsetY = $offsets[GeometryCalculator::Y];
90        }
91
92        return $this->offsetX;
93    }
94
95    /**
96     * Ignores setting the X Offset, preserving the default behavior.
97     *
98     * @return $this
99     */
100    public function setOffsetX(int $pValue = 0)
101    {
102        return $this;
103    }
104
105    /**
106     * Get Y Offset.
107     */
108    public function getOffsetY(): int
109    {
110        if (empty($this->offsetY)) {
111            $offsets = GeometryCalculator::calculateOffsets($this);
112            $this->offsetX = $offsets[GeometryCalculator::X];
113            $this->offsetY = $offsets[GeometryCalculator::Y];
114        }
115
116        return $this->offsetY;
117    }
118
119    /**
120     * Ignores setting the Y Offset, preserving the default behavior.
121     *
122     * @return $this
123     */
124    public function setOffsetY(int $pValue = 0)
125    {
126        return $this;
127    }
128
129    /**
130     * Get X Extent.
131     */
132    public function getExtentX(): int
133    {
134        if (null === $this->extentX) {
135            $extents = GeometryCalculator::calculateExtents($this);
136            $this->extentX = $extents[GeometryCalculator::X] - $this->getOffsetX();
137            $this->extentY = $extents[GeometryCalculator::Y] - $this->getOffsetY();
138        }
139
140        return $this->extentX;
141    }
142
143    /**
144     * Get Y Extent.
145     */
146    public function getExtentY(): int
147    {
148        if (null === $this->extentY) {
149            $extents = GeometryCalculator::calculateExtents($this);
150            $this->extentX = $extents[GeometryCalculator::X] - $this->getOffsetX();
151            $this->extentY = $extents[GeometryCalculator::Y] - $this->getOffsetY();
152        }
153
154        return $this->extentY;
155    }
156
157    /**
158     * Ignores setting the width, preserving the default behavior.
159     *
160     * @return self
161     */
162    public function setWidth(int $pValue = 0)
163    {
164        return $this;
165    }
166
167    /**
168     * Ignores setting the height, preserving the default behavior.
169     *
170     * @return $this
171     */
172    public function setHeight(int $pValue = 0)
173    {
174        return $this;
175    }
176
177    /**
178     * Create rich text shape.
179     *
180     * @return RichText
181     */
182    public function createRichTextShape(): RichText
183    {
184        $shape = new RichText();
185        $this->addShape($shape);
186
187        return $shape;
188    }
189
190    /**
191     * Create line shape.
192     *
193     * @param int $fromX Starting point x offset
194     * @param int $fromY Starting point y offset
195     * @param int $toX Ending point x offset
196     * @param int $toY Ending point y offset
197     *
198     * @return Line
199     */
200    public function createLineShape(int $fromX, int $fromY, int $toX, int $toY): Line
201    {
202        $shape = new Line($fromX, $fromY, $toX, $toY);
203        $this->addShape($shape);
204
205        return $shape;
206    }
207
208    /**
209     * Create chart shape.
210     *
211     * @return Chart
212     */
213    public function createChartShape(): Chart
214    {
215        $shape = new Chart();
216        $this->addShape($shape);
217
218        return $shape;
219    }
220
221    /**
222     * Create drawing shape.
223     *
224     * @return Drawing\File
225     */
226    public function createDrawingShape(): Drawing\File
227    {
228        $shape = new Drawing\File();
229        $this->addShape($shape);
230
231        return $shape;
232    }
233
234    /**
235     * Create table shape.
236     *
237     * @param int $columns Number of columns
238     *
239     * @return Table
240     */
241    public function createTableShape(int $columns = 1): Table
242    {
243        $shape = new Table($columns);
244        $this->addShape($shape);
245
246        return $shape;
247    }
248}