| Total Complexity | 10 |
| Total Lines | 93 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class Map |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var array |
||
| 9 | */ |
||
| 10 | protected $keys = []; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var array |
||
| 14 | */ |
||
| 15 | protected $values = []; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Map constructor. |
||
| 19 | * @param array $values |
||
| 20 | */ |
||
| 21 | public function __construct(array $values = []) |
||
| 22 | { |
||
| 23 | foreach ($values as $key => $value) { |
||
| 24 | $this->keys[] = $key; |
||
| 25 | $this->values[] = $value; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * @param $key |
||
| 32 | * @param $value |
||
| 33 | */ |
||
| 34 | public function set($key, $value): void |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @param $key |
||
| 42 | * @return mixed|null |
||
| 43 | */ |
||
| 44 | public function get($key) |
||
| 45 | { |
||
| 46 | $index = array_search($key, $this->keys, true); |
||
| 47 | |||
| 48 | if ($index === false) { |
||
| 49 | return null; |
||
| 50 | } |
||
| 51 | |||
| 52 | return $this->values[$index] ?? null; |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @param $key |
||
| 57 | * @return bool |
||
| 58 | */ |
||
| 59 | public function has($key): bool |
||
| 60 | { |
||
| 61 | return null !== $this->get($key); |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @param $key |
||
| 66 | */ |
||
| 67 | public function delete($key): void |
||
| 68 | { |
||
| 69 | $index = array_search($key, $this->keys); |
||
| 70 | |||
| 71 | array_splice($this->keys, $index, 1); |
||
|
|
|||
| 72 | array_splice($this->values, $index, 1); |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @return array |
||
| 77 | */ |
||
| 78 | public function keys(): array |
||
| 79 | { |
||
| 80 | return $this->keys; |
||
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return array |
||
| 85 | */ |
||
| 86 | public function values(): array |
||
| 87 | { |
||
| 88 | return $this->values; |
||
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * |
||
| 93 | */ |
||
| 94 | public function clear(): void |
||
| 98 | } |
||
| 99 | } |
||
| 100 |