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 | * This file is part of PHPWord - A pure PHP library for reading and writing |
4 | * word processing documents. |
5 | * |
6 | * PHPWord 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/PHPWord/contributors. |
12 | * |
13 | * @see https://github.com/PHPOffice/PHPWord |
14 | * |
15 | * @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3 |
16 | */ |
17 | |
18 | namespace PhpOffice\PhpWord\Collection; |
19 | |
20 | /** |
21 | * Collection abstract class. |
22 | * |
23 | * @since 0.10.0 |
24 | * @template T |
25 | */ |
26 | abstract class AbstractCollection |
27 | { |
28 | /** |
29 | * Items. |
30 | * |
31 | * @var T[] |
32 | */ |
33 | private $items = []; |
34 | |
35 | /** |
36 | * Get items. |
37 | * |
38 | * @return T[] |
39 | */ |
40 | public function getItems(): array |
41 | { |
42 | return $this->items; |
43 | } |
44 | |
45 | /** |
46 | * Get item by index. |
47 | * |
48 | * @return ?T |
49 | */ |
50 | public function getItem(int $index) |
51 | { |
52 | if (array_key_exists($index, $this->items)) { |
53 | return $this->items[$index]; |
54 | } |
55 | |
56 | return null; |
57 | } |
58 | |
59 | /** |
60 | * Set item. |
61 | * |
62 | * @param ?T $item |
63 | */ |
64 | public function setItem(int $index, $item): void |
65 | { |
66 | if (array_key_exists($index, $this->items)) { |
67 | $this->items[$index] = $item; |
68 | } |
69 | } |
70 | |
71 | /** |
72 | * Add new item. |
73 | * |
74 | * @param T $item |
75 | */ |
76 | public function addItem($item): int |
77 | { |
78 | $index = $this->countItems(); |
79 | $this->items[$index] = $item; |
80 | |
81 | return $index; |
82 | } |
83 | |
84 | /** |
85 | * Get item count. |
86 | */ |
87 | public function countItems(): int |
88 | { |
89 | return count($this->items); |
90 | } |
91 | } |