Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| ShapeCollection | |
100.00% |
15 / 15 |
|
100.00% |
5 / 5 |
10 | |
100.00% |
1 / 1 |
| getShapeCollection | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| searchShapes | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
6 | |||
| setShapeCollection | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| addShape | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| unsetShape | |
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\Traits; |
| 21 | |
| 22 | use PhpOffice\PhpPresentation\AbstractShape; |
| 23 | |
| 24 | trait ShapeCollection |
| 25 | { |
| 26 | /** |
| 27 | * Collection of shapes. |
| 28 | * |
| 29 | * @var array<int, AbstractShape> |
| 30 | */ |
| 31 | protected $shapeCollection = []; |
| 32 | |
| 33 | /** |
| 34 | * Get collection of shapes. |
| 35 | * |
| 36 | * @return array<int, AbstractShape> |
| 37 | */ |
| 38 | public function getShapeCollection(): array |
| 39 | { |
| 40 | return $this->shapeCollection; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Search into collection of shapes for a name or/and a type. |
| 45 | * |
| 46 | * @return array<int, AbstractShape> |
| 47 | */ |
| 48 | public function searchShapes(?string $name = null, ?string $type = null): array |
| 49 | { |
| 50 | $found = []; |
| 51 | foreach ($this->getShapeCollection() as $shape) { |
| 52 | if ($name && $shape->getName() !== $name) { |
| 53 | continue; |
| 54 | } |
| 55 | if ($type && get_class($shape) !== $type) { |
| 56 | continue; |
| 57 | } |
| 58 | |
| 59 | $found[] = $shape; |
| 60 | } |
| 61 | |
| 62 | return $found; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Get collection of shapes. |
| 67 | * |
| 68 | * @param array<int, AbstractShape> $shapeCollection |
| 69 | */ |
| 70 | public function setShapeCollection(array $shapeCollection = []): self |
| 71 | { |
| 72 | $this->shapeCollection = $shapeCollection; |
| 73 | |
| 74 | return $this; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * @return static |
| 79 | */ |
| 80 | public function addShape(AbstractShape $shape) |
| 81 | { |
| 82 | $this->shapeCollection[] = $shape; |
| 83 | |
| 84 | return $this; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * @return static |
| 89 | */ |
| 90 | public function unsetShape(int $key) |
| 91 | { |
| 92 | unset($this->shapeCollection[$key]); |
| 93 | |
| 94 | return $this; |
| 95 | } |
| 96 | } |