Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
55 / 55
100.00% covered (success)
100.00%
21 / 21
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractSlide
100.00% covered (success)
100.00%
55 / 55
100.00% covered (success)
100.00%
21 / 21
25
100.00% covered (success)
100.00%
1 / 1
 getOffsetX
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getOffsetY
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getExtentX
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getExtentY
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
 getHashCode
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setHashIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 createRichTextShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createLineShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createChartShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createDrawingShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createTableShape
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 createGroup
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getParent
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 rebindParent
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 getBackground
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setBackground
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getTransition
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setTransition
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getRelsIndex
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRelsIndex
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
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 * @license     http://www.gnu.org/licenses/lgpl.txt LGPL version 3
16 */
17
18declare(strict_types=1);
19
20namespace PhpOffice\PhpPresentation\Slide;
21
22use PhpOffice\PhpPresentation\ComparableInterface;
23use PhpOffice\PhpPresentation\GeometryCalculator;
24use PhpOffice\PhpPresentation\PhpPresentation;
25use PhpOffice\PhpPresentation\Shape\Chart;
26use PhpOffice\PhpPresentation\Shape\Drawing\File;
27use PhpOffice\PhpPresentation\Shape\Group;
28use PhpOffice\PhpPresentation\Shape\Line;
29use PhpOffice\PhpPresentation\Shape\RichText;
30use PhpOffice\PhpPresentation\Shape\Table;
31use PhpOffice\PhpPresentation\ShapeContainerInterface;
32use PhpOffice\PhpPresentation\Traits\ShapeCollection;
33
34abstract class AbstractSlide implements ComparableInterface, ShapeContainerInterface
35{
36    use ShapeCollection;
37
38    /**
39     * @var string
40     */
41    protected $relsIndex;
42
43    /**
44     * @var null|Transition
45     */
46    protected $slideTransition;
47
48    /**
49     * Extent Y.
50     *
51     * @var int
52     */
53    protected $extentY;
54
55    /**
56     * Extent X.
57     *
58     * @var int
59     */
60    protected $extentX;
61
62    /**
63     * Offset X.
64     *
65     * @var int
66     */
67    protected $offsetX;
68
69    /**
70     * Offset Y.
71     *
72     * @var int
73     */
74    protected $offsetY;
75
76    /**
77     * Slide identifier.
78     *
79     * @var string
80     */
81    protected $identifier;
82
83    /**
84     * Hash index.
85     *
86     * @var int
87     */
88    protected $hashIndex;
89
90    /**
91     * Parent presentation.
92     *
93     * @var null|PhpPresentation
94     */
95    protected $parent;
96
97    /**
98     * Background of the slide.
99     *
100     * @var AbstractBackground
101     */
102    protected $background;
103
104    /**
105     * Get X Offset.
106     */
107    public function getOffsetX(): int
108    {
109        if (null === $this->offsetX) {
110            $offsets = GeometryCalculator::calculateOffsets($this);
111            $this->offsetX = $offsets[GeometryCalculator::X];
112            $this->offsetY = $offsets[GeometryCalculator::Y];
113        }
114
115        return $this->offsetX;
116    }
117
118    /**
119     * Get Y Offset.
120     */
121    public function getOffsetY(): int
122    {
123        if (null === $this->offsetY) {
124            $offsets = GeometryCalculator::calculateOffsets($this);
125            $this->offsetX = $offsets[GeometryCalculator::X];
126            $this->offsetY = $offsets[GeometryCalculator::Y];
127        }
128
129        return $this->offsetY;
130    }
131
132    /**
133     * Get X Extent.
134     */
135    public function getExtentX(): int
136    {
137        if (null === $this->extentX) {
138            $extents = GeometryCalculator::calculateExtents($this);
139            $this->extentX = $extents[GeometryCalculator::X];
140            $this->extentY = $extents[GeometryCalculator::Y];
141        }
142
143        return $this->extentX;
144    }
145
146    /**
147     * Get Y Extent.
148     */
149    public function getExtentY(): int
150    {
151        if (null === $this->extentY) {
152            $extents = GeometryCalculator::calculateExtents($this);
153            $this->extentX = $extents[GeometryCalculator::X];
154            $this->extentY = $extents[GeometryCalculator::Y];
155        }
156
157        return $this->extentY;
158    }
159
160    /**
161     * Get hash code.
162     *
163     * @return string Hash code
164     */
165    public function getHashCode(): string
166    {
167        return md5($this->identifier . __CLASS__);
168    }
169
170    /**
171     * Get hash index.
172     *
173     * Note that this index may vary during script execution! Only reliable moment is
174     * while doing a write of a workbook and when changes are not allowed.
175     *
176     * @return null|int Hash index
177     */
178    public function getHashIndex(): ?int
179    {
180        return $this->hashIndex;
181    }
182
183    /**
184     * Set hash index.
185     *
186     * Note that this index may vary during script execution! Only reliable moment is
187     * while doing a write of a workbook and when changes are not allowed.
188     *
189     * @param int $value Hash index
190     *
191     * @return $this
192     */
193    public function setHashIndex(int $value)
194    {
195        $this->hashIndex = $value;
196
197        return $this;
198    }
199
200    /**
201     * Create rich text shape.
202     */
203    public function createRichTextShape(): RichText
204    {
205        $shape = new RichText();
206        $this->addShape($shape);
207
208        return $shape;
209    }
210
211    /**
212     * Create line shape.
213     *
214     * @param int $fromX Starting point x offset
215     * @param int $fromY Starting point y offset
216     * @param int $toX Ending point x offset
217     * @param int $toY Ending point y offset
218     */
219    public function createLineShape(int $fromX, int $fromY, int $toX, int $toY): Line
220    {
221        $shape = new Line($fromX, $fromY, $toX, $toY);
222        $this->addShape($shape);
223
224        return $shape;
225    }
226
227    /**
228     * Create chart shape.
229     */
230    public function createChartShape(): Chart
231    {
232        $shape = new Chart();
233        $this->addShape($shape);
234
235        return $shape;
236    }
237
238    /**
239     * Create drawing shape.
240     */
241    public function createDrawingShape(): File
242    {
243        $shape = new File();
244        $this->addShape($shape);
245
246        return $shape;
247    }
248
249    /**
250     * Create table shape.
251     *
252     * @param int $columns Number of columns
253     */
254    public function createTableShape(int $columns = 1): Table
255    {
256        $shape = new Table($columns);
257        $this->addShape($shape);
258
259        return $shape;
260    }
261
262    /**
263     * Creates a group within this slide.
264     */
265    public function createGroup(): Group
266    {
267        $shape = new Group();
268        $this->addShape($shape);
269
270        return $shape;
271    }
272
273    /**
274     * Get parent.
275     */
276    public function getParent(): ?PhpPresentation
277    {
278        return $this->parent;
279    }
280
281    /**
282     * Re-bind parent.
283     */
284    public function rebindParent(PhpPresentation $parent): self
285    {
286        $this->parent->removeSlideByIndex($this->parent->getIndex($this));
287        $this->parent = $parent;
288
289        return $this;
290    }
291
292    public function getBackground(): ?AbstractBackground
293    {
294        return $this->background;
295    }
296
297    public function setBackground(?AbstractBackground $background = null): self
298    {
299        $this->background = $background;
300
301        return $this;
302    }
303
304    public function getTransition(): ?Transition
305    {
306        return $this->slideTransition;
307    }
308
309    public function setTransition(?Transition $transition = null): self
310    {
311        $this->slideTransition = $transition;
312
313        return $this;
314    }
315
316    public function getRelsIndex(): string
317    {
318        return $this->relsIndex;
319    }
320
321    public function setRelsIndex(string $indexName): self
322    {
323        $this->relsIndex = $indexName;
324
325        return $this;
326    }
327}