Skip to content

Commit 15dbb50

Browse files
committed
improved exceptions for cypher lists and objects
1 parent 61e8f9d commit 15dbb50

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/Types/AbstractCypherObject.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
use ArrayAccess;
1818
use ArrayIterator;
1919
use BadMethodCallException;
20-
use function get_class;
21-
use InvalidArgumentException;
2220
use IteratorAggregate;
2321
use JsonSerializable;
22+
use OutOfBoundsException;
2423
use function sprintf;
2524

2625
/**
@@ -73,7 +72,7 @@ final public function offsetGet($offset)
7372
{
7473
$serialized = $this->toArray();
7574
if (!array_key_exists($offset, $serialized)) {
76-
throw new InvalidArgumentException("Offset: $offset does not exists for class: ".static::class);
75+
throw new OutOfBoundsException("Offset: \"$offset\" does not exists in object of instance: ".static::class);
7776
}
7877

7978
return $serialized[$offset];
@@ -85,14 +84,14 @@ final public function offsetGet($offset)
8584
*/
8685
final public function offsetSet($offset, $value): void
8786
{
88-
throw new BadMethodCallException(sprintf('%s is immutable', get_class($this)));
87+
throw new BadMethodCallException(sprintf('%s is immutable', static::class));
8988
}
9089

9190
/**
9291
* @param TKey $offset
9392
*/
9493
final public function offsetUnset($offset): void
9594
{
96-
throw new BadMethodCallException(sprintf('%s is immutable', get_class($this)));
95+
throw new BadMethodCallException(sprintf('%s is immutable', static::class));
9796
}
9897
}

src/Types/CypherList.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use function array_key_exists;
1717
use function array_key_last;
1818
use function array_slice;
19-
use BadMethodCallException;
2019
use function is_int;
2120
use OutOfBoundsException;
2221
use function sort;
@@ -72,7 +71,7 @@ public function last()
7271
{
7372
$key = array_key_last($this->sequence);
7473
if (!is_int($key)) {
75-
throw new BadMethodCallException('Cannot grab last element from an empty list');
74+
throw new OutOfBoundsException('Cannot grab last element of an empty list');
7675
}
7776

7877
return $this->sequence[$key];
@@ -144,7 +143,7 @@ public static function fromIterable(iterable $iterable): AbstractCypherSequence
144143
public function get(int $key)
145144
{
146145
if (!array_key_exists($key, $this->sequence)) {
147-
throw new OutOfBoundsException();
146+
throw new OutOfBoundsException(sprintf('Cannot get item in sequence at position: %s', $key));
148147
}
149148

150149
return $this->sequence[$key];

0 commit comments

Comments
 (0)