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 | class Collection implements \Countable, \ArrayAccess |
| 6 | { |
| 7 | protected $entities = []; |
| 8 | |
| 9 | final public function offsetExists($offset): bool |
| 10 | { |
| 11 | return array_key_exists($offset, $this->entities); |
| 12 | } |
| 13 | |
| 14 | final public function offsetGet($offset) |
| 15 | { |
| 16 | if ($this->offsetExists($offset)) { |
| 17 | return $this->entities[$offset]; |
| 18 | } |
| 19 | throw new \InvalidArgumentException(__METHOD__ . " offset({$offset}) has not been set!"); |
| 20 | } |
| 21 | |
| 22 | final public function offsetSet($offset, $value): Collection |
| 23 | { |
| 24 | if (!$value instanceof Base) { |
| 25 | throw new \InvalidArgumentException( |
| 26 | __METHOD__ . ' $value must be an instance of \\BO\\Zmsdldb\\Importer\\MySQL\\Entity\\Base' |
| 27 | ); |
| 28 | } |
| 29 | if (null === $offset) { |
| 30 | $this->entities[] = $value; |
| 31 | } else { |
| 32 | $this->entities[$offset] = $value; |
| 33 | } |
| 34 | return $this; |
| 35 | } |
| 36 | |
| 37 | final public function offsetUnset($offset): Collection |
| 38 | { |
| 39 | unset($this->entities[$offset]); |
| 40 | return $this; |
| 41 | } |
| 42 | |
| 43 | final public function count(): int |
| 44 | { |
| 45 | return count($this->entities); |
| 46 | } |
| 47 | |
| 48 | public function saveEntities() |
| 49 | { |
| 50 | try { |
| 51 | foreach ($this->entities as $entity) { |
| 52 | $entity->save(); |
| 53 | } |
| 54 | } catch (\Exception $e) { |
| 55 | throw $e; |
| 56 | } |
| 57 | } |
| 58 | } |