Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
55.00% |
11 / 20 |
|
45.45% |
5 / 11 |
CRAP | |
0.00% |
0 / 1 |
| TaskLogCollection | |
55.00% |
11 / 20 |
|
45.45% |
5 / 11 |
31.86 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| createFromArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| createEmptyCollection | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| toArray | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIterator | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isEmpty | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| first | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| last | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIds | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2017 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\taskQueue\TaskLog; |
| 23 | |
| 24 | use oat\tao\model\taskQueue\TaskLog\Entity\EntityInterface; |
| 25 | use oat\tao\model\taskQueue\TaskLog\Entity\TaskLogEntity; |
| 26 | use Traversable; |
| 27 | |
| 28 | class TaskLogCollection implements CollectionInterface |
| 29 | { |
| 30 | /** @var EntityInterface[] */ |
| 31 | private $taskLogs = []; |
| 32 | |
| 33 | /** |
| 34 | * @param EntityInterface[] $taskLogs |
| 35 | */ |
| 36 | public function __construct(array $taskLogs) |
| 37 | { |
| 38 | $this->taskLogs = $taskLogs; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @param array $rows |
| 43 | * @return TaskLogCollection |
| 44 | * |
| 45 | * @throws \Exception |
| 46 | */ |
| 47 | public static function createFromArray(array $rows, string $dateFormat) |
| 48 | { |
| 49 | $logs = []; |
| 50 | |
| 51 | foreach ($rows as $row) { |
| 52 | $logs[] = TaskLogEntity::createFromArray($row, $dateFormat); |
| 53 | } |
| 54 | |
| 55 | return new static($logs); |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * @return TaskLogCollection |
| 60 | */ |
| 61 | public static function createEmptyCollection() |
| 62 | { |
| 63 | return new static([]); |
| 64 | } |
| 65 | |
| 66 | public function jsonSerialize() |
| 67 | { |
| 68 | return $this->toArray(); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * @return array |
| 73 | */ |
| 74 | public function toArray() |
| 75 | { |
| 76 | $data = []; |
| 77 | |
| 78 | foreach ($this->taskLogs as $taskLog) { |
| 79 | $data[] = $taskLog->toArray(); |
| 80 | } |
| 81 | |
| 82 | return $data; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return int |
| 87 | */ |
| 88 | public function count(): int |
| 89 | { |
| 90 | return count($this->taskLogs); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return \ArrayIterator |
| 95 | */ |
| 96 | public function getIterator(): Traversable |
| 97 | { |
| 98 | return new \ArrayIterator($this->taskLogs); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * @return bool |
| 103 | */ |
| 104 | public function isEmpty() |
| 105 | { |
| 106 | return empty($this->taskLogs); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * @return TaskLogEntity |
| 111 | */ |
| 112 | public function first() |
| 113 | { |
| 114 | return reset($this->taskLogs); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * @return TaskLogEntity |
| 119 | */ |
| 120 | public function last() |
| 121 | { |
| 122 | return end($this->taskLogs); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * @inheritdoc |
| 127 | */ |
| 128 | public function getIds() |
| 129 | { |
| 130 | $ids = []; |
| 131 | /** @var EntityInterface $item */ |
| 132 | foreach ($this->taskLogs as $item) { |
| 133 | $ids[] = $item->getId(); |
| 134 | } |
| 135 | |
| 136 | return $ids; |
| 137 | } |
| 138 | } |