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