Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| AbstractCollection | |
100.00% |
10 / 10 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| getItems | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getItem | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setItem | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| addItem | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| countItems | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This file is part of PHPWord - A pure PHP library for reading and writing |
| 5 | * word processing documents. |
| 6 | * |
| 7 | * PHPWord is free software distributed under the terms of the GNU Lesser |
| 8 | * General Public License version 3 as published by the Free Software Foundation. |
| 9 | * |
| 10 | * For the full copyright and license information, please read the LICENSE |
| 11 | * file that was distributed with this source code. For the full list of |
| 12 | * contributors, visit https://github.com/PHPOffice/PHPWord/contributors. |
| 13 | * |
| 14 | * @see https://github.com/PHPOffice/PHPWord |
| 15 | * |
| 16 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
| 17 | */ |
| 18 | |
| 19 | namespace PhpOffice\PhpWord\Collection; |
| 20 | |
| 21 | /** |
| 22 | * Collection abstract class. |
| 23 | * |
| 24 | * @since 0.10.0 |
| 25 | * |
| 26 | * @template T |
| 27 | */ |
| 28 | abstract class AbstractCollection |
| 29 | { |
| 30 | /** |
| 31 | * Items. |
| 32 | * |
| 33 | * @var T[] |
| 34 | */ |
| 35 | private $items = []; |
| 36 | |
| 37 | /** |
| 38 | * Get items. |
| 39 | * |
| 40 | * @return T[] |
| 41 | */ |
| 42 | public function getItems(): array |
| 43 | { |
| 44 | return $this->items; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Get item by index. |
| 49 | * |
| 50 | * @return ?T |
| 51 | */ |
| 52 | public function getItem(int $index) |
| 53 | { |
| 54 | if (array_key_exists($index, $this->items)) { |
| 55 | return $this->items[$index]; |
| 56 | } |
| 57 | |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Set item. |
| 63 | * |
| 64 | * @param ?T $item |
| 65 | */ |
| 66 | public function setItem(int $index, $item): void |
| 67 | { |
| 68 | if (array_key_exists($index, $this->items)) { |
| 69 | $this->items[$index] = $item; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Add new item. |
| 75 | * |
| 76 | * @param T $item |
| 77 | */ |
| 78 | public function addItem($item): int |
| 79 | { |
| 80 | $index = $this->countItems(); |
| 81 | $this->items[$index] = $item; |
| 82 | |
| 83 | return $index; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Get item count. |
| 88 | */ |
| 89 | public function countItems(): int |
| 90 | { |
| 91 | return count($this->items); |
| 92 | } |
| 93 | } |