Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
CRAP | |
100.00% |
15 / 15 |
| Dictionary | |
100.00% |
1 / 1 |
|
100.00% |
7 / 7 |
9 | |
100.00% |
15 / 15 |
| add($key, $value) | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| set($key, $value) | |
100.00% |
1 / 1 |
2 | |
100.00% |
4 / 4 |
|||
| keys() | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| offsetExists($offset) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| offsetGet($offset) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| offsetSet($offset, $value) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| offsetUnset($offset) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| <?php | |
| // Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information. | |
| namespace Easy\Collections; | |
| use InvalidArgumentException; | |
| /** | |
| * Represents a collection of keys and values. | |
| */ | |
| class Dictionary extends CollectionArray implements IDictionary | |
| { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function add($key, $value) | |
| { | |
| if ($this->contains($key)) { | |
| throw new InvalidArgumentException('That key already exists!'); | |
| } | |
| $this->set($key, $value); | |
| return $this; | |
| } | |
| public function set($key, $value) | |
| { | |
| if ($key === null) { | |
| throw new InvalidArgumentException("Can't use 'null' as key!"); | |
| } | |
| $this->array[$key] = $value; | |
| return $this; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function keys() | |
| { | |
| return array_keys($this->array); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetExists($offset) | |
| { | |
| return $this->contains($offset); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetGet($offset) | |
| { | |
| return $this->get($offset); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetSet($offset, $value) | |
| { | |
| $this->set($offset, $value); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetUnset($offset) | |
| { | |
| $this->remove($offset); | |
| } | |
| } |