Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
50.00% |
4 / 8 |
CRAP | |
48.28% |
14 / 29 |
| ArrayList | |
0.00% |
0 / 1 |
|
50.00% |
4 / 8 |
51.43 | |
48.28% |
14 / 29 |
| add($item) | |
100.00% |
1 / 1 |
1 | |
100.00% |
2 / 2 |
|||
| addAll($items) | |
0.00% |
0 / 1 |
1.12 | |
50.00% |
1 / 2 |
|||
| indexOf($item) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| insert($index, $item) | |
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 10 |
|||
| offsetExists($offset) | |
0.00% |
0 / 1 |
3.58 | |
60.00% |
3 / 5 |
|||
| offsetGet($offset) | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| offsetSet($offset, $value) | |
0.00% |
0 / 1 |
3.33 | |
66.67% |
4 / 6 |
|||
| 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 Easy\Collections\CollectionArray; | |
| use InvalidArgumentException; | |
| /** | |
| * Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists. | |
| */ | |
| class ArrayList extends CollectionArray implements IList | |
| { | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function add($item) | |
| { | |
| array_push($this->array, $item); | |
| return $this; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function addAll($items) | |
| { | |
| $this->addMultiple($items); | |
| return $this; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function indexOf($item) | |
| { | |
| return array_search($item, $this->array, true); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function insert($index, $item) | |
| { | |
| if (!is_numeric($index)) { | |
| throw new InvalidArgumentException('The index must be numeric'); | |
| } | |
| if ($index < 0 || $index >= $this->Count()) { | |
| throw new InvalidArgumentException('The index is out of bounds (must be >=0 and <= size of te array)'); | |
| } | |
| $current = $this->Count() - 1; | |
| for (; $current >= $index; $current--) { | |
| $this->array[$current + 1] = $this->array[$current]; | |
| } | |
| $this->array[$index] = $item; | |
| return $this; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetExists($offset) | |
| { | |
| if (!is_numeric($offset)) { | |
| throw new InvalidArgumentException('The offset value must be numeric'); | |
| } | |
| if ($offset < 0) { | |
| throw new InvalidArgumentException('The option value must be a number > 0'); | |
| } | |
| return array_key_exists((int) $offset, $this->array); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetGet($offset) | |
| { | |
| return $this->get($offset); | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetSet($offset, $value) | |
| { | |
| if (!is_numeric($offset)) { | |
| throw new InvalidArgumentException('The offset value must be numeric'); | |
| } | |
| if ($offset < 0) { | |
| throw new InvalidArgumentException('The option value must be a number > 0'); | |
| } | |
| $this->array[(int) $offset] = $value; | |
| } | |
| /** | |
| * {@inheritdoc} | |
| */ | |
| public function offsetUnset($offset) | |
| { | |
| $this->remove($offset); | |
| } | |
| } |