Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Collection | |
0.00% |
0 / 19 |
|
0.00% |
0 / 6 |
132 | |
0.00% |
0 / 1 |
| offsetExists | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| offsetGet | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| offsetSet | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| offsetUnset | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| count | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| saveEntities | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BO\Zmsdldb\Importer\MySQL\Entity; |
| 4 | |
| 5 | /** |
| 6 | * @implements \ArrayAccess<int|string, Base> |
| 7 | */ |
| 8 | class Collection implements \Countable, \ArrayAccess |
| 9 | { |
| 10 | protected $entities = []; |
| 11 | |
| 12 | #[\Override] |
| 13 | final public function offsetExists($offset): bool |
| 14 | { |
| 15 | return array_key_exists($offset, $this->entities); |
| 16 | } |
| 17 | |
| 18 | #[\Override] |
| 19 | final public function offsetGet($offset) |
| 20 | { |
| 21 | if ($this->offsetExists($offset)) { |
| 22 | return $this->entities[$offset]; |
| 23 | } |
| 24 | throw new \InvalidArgumentException(__METHOD__ . " offset({$offset}) has not been set!"); |
| 25 | } |
| 26 | |
| 27 | #[\Override] |
| 28 | final public function offsetSet($offset, $value): Collection |
| 29 | { |
| 30 | if (!$value instanceof Base) { |
| 31 | throw new \InvalidArgumentException( |
| 32 | __METHOD__ . ' $value must be an instance of \\BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Base' |
| 33 | ); |
| 34 | } |
| 35 | if (null === $offset) { |
| 36 | $this->entities[] = $value; |
| 37 | } else { |
| 38 | $this->entities[$offset] = $value; |
| 39 | } |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | #[\Override] |
| 44 | final public function offsetUnset($offset): Collection |
| 45 | { |
| 46 | unset($this->entities[$offset]); |
| 47 | return $this; |
| 48 | } |
| 49 | |
| 50 | #[\Override] |
| 51 | final public function count(): int |
| 52 | { |
| 53 | return count($this->entities); |
| 54 | } |
| 55 | |
| 56 | public function saveEntities() |
| 57 | { |
| 58 | try { |
| 59 | foreach ($this->entities as $entity) { |
| 60 | $entity->save(); |
| 61 | } |
| 62 | } catch (\Exception $e) { |
| 63 | throw $e; |
| 64 | } |
| 65 | } |
| 66 | } |