| Total Complexity | 9 |
| Total Lines | 66 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php declare(strict_types=1); |
||
| 12 | class GatewayMock |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var array<int, array> |
||
| 16 | */ |
||
| 17 | private $collection = []; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Add item in collection and return id assigned |
||
| 21 | */ |
||
| 22 | public function create(array $item): int |
||
| 23 | { |
||
| 24 | $itemId = $this->count() + 1; |
||
| 25 | $this->collection[$itemId] = $item; |
||
| 26 | |||
| 27 | return $itemId; |
||
| 28 | } |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Get item in collection |
||
| 32 | */ |
||
| 33 | public function read(int $itemId): ?array |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Edit item in collection |
||
| 44 | */ |
||
| 45 | public function update(int $itemId, array $item): bool |
||
| 46 | { |
||
| 47 | if (!$this->exist($itemId)) { |
||
| 48 | return false; |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->collection[$itemId] = $item; |
||
| 52 | |||
| 53 | return true; |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Remove item in collection |
||
| 58 | */ |
||
| 59 | public function delete(int $itemId): bool |
||
| 60 | { |
||
| 61 | if (!$this->exist($itemId)) { |
||
| 62 | return false; |
||
| 63 | } |
||
| 64 | |||
| 65 | unset($this->collection[$itemId]); |
||
| 66 | |||
| 67 | return true; |
||
| 68 | } |
||
| 69 | |||
| 70 | private function exist(int $itemId): bool |
||
| 73 | } |
||
| 74 | |||
| 75 | private function count(): int |
||
| 78 | } |
||
| 79 | } |
||
| 80 |