Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
29 / 29
CRAP
100.00% covered (success)
100.00%
68 / 68
AbstractShape
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
29 / 29
40
100.00% covered (success)
100.00%
68 / 68
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
6 / 6
 __clone
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
5 / 5
 getContainer
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setContainer
100.00% covered (success)
100.00%
1 / 1
6
100.00% covered (success)
100.00%
15 / 15
 getOffsetX
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setOffsetX
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getOffsetY
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setOffsetY
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getWidth
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setWidth
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getHeight
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%
2 / 2
 setWidthAndHeight
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 getRotation
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setRotation
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getFill
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setFill
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getBorder
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getShadow
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setShadow
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 hasHyperlink
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getHyperlink
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 setHyperlink
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 getHashCode
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
1 / 1
 getHashIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setHashIndex
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 isPlaceholder
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getPlaceholder
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 setPlaceHolder
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
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;
22
23use PhpOffice\PhpPresentation\Exception\ShapeContainerAlreadyAssignedException;
24use PhpOffice\PhpPresentation\Shape\Hyperlink;
25use PhpOffice\PhpPresentation\Shape\Placeholder;
26use PhpOffice\PhpPresentation\Style\Border;
27use PhpOffice\PhpPresentation\Style\Fill;
28use PhpOffice\PhpPresentation\Style\Shadow;
29
30/**
31 * Abstract shape.
32 */
33abstract class AbstractShape implements ComparableInterface
34{
35    /**
36     * Container.
37     *
38     * @var ShapeContainerInterface|null
39     */
40    protected $container;
41
42    /**
43     * Offset X.
44     *
45     * @var int
46     */
47    protected $offsetX;
48
49    /**
50     * Offset Y.
51     *
52     * @var int
53     */
54    protected $offsetY;
55
56    /**
57     * Width.
58     *
59     * @var int
60     */
61    protected $width;
62
63    /**
64     * Height.
65     *
66     * @var int
67     */
68    protected $height;
69
70    /**
71     * @var Fill|null
72     */
73    private $fill;
74
75    /**
76     * Border.
77     *
78     * @var Border
79     */
80    private $border;
81
82    /**
83     * Rotation.
84     *
85     * @var int
86     */
87    protected $rotation;
88
89    /**
90     * Shadow.
91     *
92     * @var Shadow|null
93     */
94    protected $shadow;
95
96    /**
97     * @var Hyperlink|null
98     */
99    protected $hyperlink;
100
101    /**
102     * @var Placeholder|null
103     */
104    protected $placeholder;
105
106    /**
107     * Hash index.
108     *
109     * @var int
110     */
111    private $hashIndex;
112
113    /**
114     * Create a new self.
115     */
116    public function __construct()
117    {
118        $this->offsetX = $this->offsetY = $this->width = $this->height = $this->rotation = 0;
119        $this->fill = new Fill();
120        $this->shadow = new Shadow();
121        $this->border = new Border();
122        $this->border->setLineStyle(Style\Border::LINE_NONE);
123    }
124
125    /**
126     * Magic Method : clone.
127     */
128    public function __clone()
129    {
130        $this->container = null;
131        $this->fill = clone $this->fill;
132        $this->border = clone $this->border;
133        $this->shadow = clone $this->shadow;
134    }
135
136    /**
137     * Get Container, Slide or Group.
138     */
139    public function getContainer(): ?ShapeContainerInterface
140    {
141        return $this->container;
142    }
143
144    /**
145     * Set Container, Slide or Group.
146     *
147     * @param ShapeContainerInterface $pValue
148     * @param bool $pOverrideOld If a Slide has already been assigned, overwrite it and remove image from old Slide?
149     *
150     * @throws ShapeContainerAlreadyAssignedException
151     *
152     * @return $this
153     */
154    public function setContainer(ShapeContainerInterface $pValue = null, $pOverrideOld = false)
155    {
156        if (is_null($this->container)) {
157            // Add drawing to ShapeContainerInterface
158            $this->container = $pValue;
159            if (!is_null($this->container)) {
160                $this->container->getShapeCollection()->append($this);
161            }
162        } else {
163            if ($pOverrideOld) {
164                // Remove drawing from old ShapeContainerInterface
165                $iterator = $this->container->getShapeCollection()->getIterator();
166
167                while ($iterator->valid()) {
168                    if ($iterator->current()->getHashCode() == $this->getHashCode()) {
169                        $this->container->getShapeCollection()->offsetUnset($iterator->key());
170                        $this->container = null;
171                        break;
172                    }
173                    $iterator->next();
174                }
175
176                // Set new \PhpOffice\PhpPresentation\Slide
177                $this->setContainer($pValue);
178            } else {
179                throw new ShapeContainerAlreadyAssignedException(self::class);
180            }
181        }
182
183        return $this;
184    }
185
186    /**
187     * Get OffsetX.
188     */
189    public function getOffsetX(): int
190    {
191        return $this->offsetX;
192    }
193
194    /**
195     * Set OffsetX.
196     *
197     * @return $this
198     */
199    public function setOffsetX(int $pValue = 0)
200    {
201        $this->offsetX = $pValue;
202
203        return $this;
204    }
205
206    /**
207     * Get OffsetY.
208     *
209     * @return int
210     */
211    public function getOffsetY()
212    {
213        return $this->offsetY;
214    }
215
216    /**
217     * Set OffsetY.
218     *
219     * @return $this
220     */
221    public function setOffsetY(int $pValue = 0)
222    {
223        $this->offsetY = $pValue;
224
225        return $this;
226    }
227
228    /**
229     * Get Width.
230     *
231     * @return int
232     */
233    public function getWidth()
234    {
235        return $this->width;
236    }
237
238    /**
239     * Set Width.
240     *
241     * @return $this
242     */
243    public function setWidth(int $pValue = 0)
244    {
245        $this->width = $pValue;
246
247        return $this;
248    }
249
250    /**
251     * Get Height.
252     *
253     * @return int
254     */
255    public function getHeight()
256    {
257        return $this->height;
258    }
259
260    /**
261     * Set Height.
262     *
263     * @return $this
264     */
265    public function setHeight(int $pValue = 0)
266    {
267        $this->height = $pValue;
268
269        return $this;
270    }
271
272    /**
273     * Set width and height with proportional resize.
274     *
275     * @return self
276     */
277    public function setWidthAndHeight(int $width = 0, int $height = 0)
278    {
279        $this->width = $width;
280        $this->height = $height;
281
282        return $this;
283    }
284
285    /**
286     * Get Rotation.
287     *
288     * @return int
289     */
290    public function getRotation()
291    {
292        return $this->rotation;
293    }
294
295    /**
296     * Set Rotation.
297     *
298     * @param int $pValue
299     *
300     * @return $this
301     */
302    public function setRotation($pValue = 0)
303    {
304        $this->rotation = $pValue;
305
306        return $this;
307    }
308
309    public function getFill(): ?Fill
310    {
311        return $this->fill;
312    }
313
314    public function setFill(Fill $pValue = null): self
315    {
316        $this->fill = $pValue;
317
318        return $this;
319    }
320
321    public function getBorder(): Border
322    {
323        return $this->border;
324    }
325
326    public function getShadow(): ?Shadow
327    {
328        return $this->shadow;
329    }
330
331    /**
332     * @return $this
333     */
334    public function setShadow(Shadow $pValue = null)
335    {
336        $this->shadow = $pValue;
337
338        return $this;
339    }
340
341    /**
342     * Has Hyperlink?
343     *
344     * @return bool
345     */
346    public function hasHyperlink()
347    {
348        return !is_null($this->hyperlink);
349    }
350
351    /**
352     * Get Hyperlink
353     */
354    public function getHyperlink(): Hyperlink
355    {
356        if (is_null($this->hyperlink)) {
357            $this->hyperlink = new Hyperlink();
358        }
359
360        return $this->hyperlink;
361    }
362
363    /**
364     * Set Hyperlink
365     */
366    public function setHyperlink(Hyperlink $pHyperlink = null): self
367    {
368        $this->hyperlink = $pHyperlink;
369
370        return $this;
371    }
372
373    /**
374     * Get hash code.
375     *
376     * @return string Hash code
377     */
378    public function getHashCode(): string
379    {
380        return md5((is_object($this->container) ? $this->container->getHashCode() : '') . $this->offsetX . $this->offsetY . $this->width . $this->height . $this->rotation . (is_null($this->getFill()) ? '' : $this->getFill()->getHashCode()) . (is_null($this->shadow) ? '' : $this->shadow->getHashCode()) . (is_null($this->hyperlink) ? '' : $this->hyperlink->getHashCode()) . __CLASS__);
381    }
382
383    /**
384     * Get hash index.
385     *
386     * Note that this index may vary during script execution! Only reliable moment is
387     * while doing a write of a workbook and when changes are not allowed.
388     *
389     * @return int|null Hash index
390     */
391    public function getHashIndex(): ?int
392    {
393        return $this->hashIndex;
394    }
395
396    /**
397     * Set hash index.
398     *
399     * Note that this index may vary during script execution! Only reliable moment is
400     * while doing a write of a workbook and when changes are not allowed.
401     *
402     * @param int $value Hash index
403     *
404     * @return $this
405     */
406    public function setHashIndex(int $value)
407    {
408        $this->hashIndex = $value;
409
410        return $this;
411    }
412
413    public function isPlaceholder(): bool
414    {
415        return !is_null($this->placeholder);
416    }
417
418    public function getPlaceholder(): ?Placeholder
419    {
420        if (!$this->isPlaceholder()) {
421            return null;
422        }
423
424        return $this->placeholder;
425    }
426
427    public function setPlaceHolder(Placeholder $placeholder): self
428    {
429        $this->placeholder = $placeholder;
430
431        return $this;
432    }
433}