Skip to content

Commit cbf78c1

Browse files
committed
Remove assertions for out of bounds Tuple array access
1 parent b891948 commit cbf78c1

File tree

2 files changed

+2
-13
lines changed

2 files changed

+2
-13
lines changed

src/TupleTrait.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ public function offsetExists($offset): bool
4444
*/
4545
public function offsetGet($offset): mixed
4646
{
47-
assert($offset === 0 || $offset === 1);
48-
4947
return match ($offset) {
5048
0 => $this->value,
5149
1 => $this->parameters,
50+
default => null,
5251
};
5352
}
5453

@@ -58,8 +57,6 @@ public function offsetGet($offset): mixed
5857
*/
5958
public function offsetSet($offset, $value): void
6059
{
61-
assert($offset === 0 || $offset === 1);
62-
6360
if ($offset === 0) {
6461
$this->value = $value;
6562
} elseif ($offset === 1) {
@@ -75,8 +72,6 @@ public function offsetSet($offset, $value): void
7572
*/
7673
public function offsetUnset($offset): void
7774
{
78-
assert($offset === 0 || $offset === 1);
79-
8075
if ($offset === 0) {
8176
$this->value = null;
8277
} elseif ($offset === 1) {

tests/ItemTest.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,7 @@ public function testArrayIndexIsset(): void
5454
public function testArrayOutOfBounds(): void
5555
{
5656
$item = new Item(true);
57-
try {
58-
$this->assertEmpty($item[2]); // @phpstan-ignore-line
59-
} catch (\AssertionError) { // @phpstan-ignore-line
60-
$this->addToAssertionCount(1);
61-
return;
62-
}
63-
$this->fail();
57+
$this->assertEmpty($item[2]); // @phpstan-ignore-line
6458
}
6559

6660
public function testArrayUnset(): void

0 commit comments

Comments
 (0)