Skip to content

Commit 19fb9fc

Browse files
committed
Remove get()/set() helpers, switch tests to offsetGet/offsetSet
1 parent 5a34ac7 commit 19fb9fc

File tree

5 files changed

+10
-70
lines changed

5 files changed

+10
-70
lines changed

ext/collections/collections_deque.c

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -805,16 +805,6 @@ static zend_always_inline void collections_deque_get_value_at_offset(zval *retur
805805
RETURN_COPY(collections_deque_get_entry_at_offset(&intern->array, offset));
806806
}
807807

808-
PHP_METHOD(Collections_Deque, get)
809-
{
810-
zend_long offset;
811-
ZEND_PARSE_PARAMETERS_START(1, 1)
812-
Z_PARAM_LONG(offset)
813-
ZEND_PARSE_PARAMETERS_END();
814-
815-
collections_deque_get_value_at_offset(return_value, ZEND_THIS, offset);
816-
}
817-
818808
PHP_METHOD(Collections_Deque, offsetGet)
819809
{
820810
zval *offset_zv;
@@ -914,18 +904,6 @@ static void collections_deque_write_dimension(zend_object *object, zval *offset_
914904
collections_deque_set_value_at_offset(object, offset, value);
915905
}
916906

917-
PHP_METHOD(Collections_Deque, set)
918-
{
919-
zend_long offset;
920-
zval *value;
921-
ZEND_PARSE_PARAMETERS_START(2, 2)
922-
Z_PARAM_LONG(offset)
923-
Z_PARAM_ZVAL(value)
924-
ZEND_PARSE_PARAMETERS_END();
925-
926-
collections_deque_set_value_at_offset(Z_OBJ_P(ZEND_THIS), offset, value);
927-
}
928-
929907
PHP_METHOD(Collections_Deque, offsetSet)
930908
{
931909
zval *offset_zv, *value;

ext/collections/collections_deque.stub.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,7 @@ public function top(): mixed {}
6767

6868
/** Returns a list of the elements from front to back. */
6969
public function toArray(): array {}
70-
/* Get and set are strictly typed, unlike offsetGet/offsetSet. */
71-
/**
72-
* Returns the value at offset $offset (relative to the start of the Deque)
73-
* @throws OutOfBoundsException if the value of (int)$offset is not within the bounds of this vector
74-
*/
75-
public function get(int $offset): mixed {}
76-
/**
77-
* Sets the value at offset $offset (relative to the start of the Deque) to $value
78-
* @throws OutOfBoundsException if the value of (int)$offset is not within the bounds of this vector
79-
*/
80-
public function set(int $offset, mixed $value): void {}
70+
8171
// Must be mixed for compatibility with ArrayAccess
8272
/**
8373
* Returns the value at offset (int)$offset (relative to the start of the Deque)

ext/collections/collections_deque_arginfo.h

Lines changed: 1 addition & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/collections/tests/Deque/offsetGet.phpt

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ function expect_throws(Closure $cb): void {
1414
expect_throws(fn() => (new ReflectionClass(Collections\Deque::class))->newInstanceWithoutConstructor());
1515
$it = new Collections\Deque(['first' => new stdClass()]);
1616
var_dump($it->offsetGet(0));
17-
var_dump($it->get(0));
1817
expect_throws(fn() => $it->offsetSet(1,'x'));
1918
expect_throws(fn() => $it->offsetUnset(0));
2019
var_dump($it->offsetGet('0'));
@@ -23,20 +22,15 @@ var_dump($it->offsetExists(1));
2322
var_dump($it->offsetExists('1'));
2423
var_dump($it->offsetExists(PHP_INT_MAX));
2524
var_dump($it->offsetExists(PHP_INT_MIN));
26-
expect_throws(fn() => $it->get(1));
27-
expect_throws(fn() => $it->get(-1));
25+
expect_throws(fn() => $it->offsetGet(1));
26+
expect_throws(fn() => $it->offsetGet(-1));
2827
echo "Invalid offsetGet calls\n";
2928
expect_throws(fn() => $it->offsetGet(PHP_INT_MAX));
3029
expect_throws(fn() => $it->offsetGet(PHP_INT_MIN));
3130
expect_throws(fn() => $it->offsetGet(1));
32-
expect_throws(fn() => $it->get(PHP_INT_MAX));
33-
expect_throws(fn() => $it->get(PHP_INT_MIN));
34-
expect_throws(fn() => $it->get(1));
35-
expect_throws(fn() => $it->get(-1));
36-
expect_throws(fn() => $it->offsetGet(1));
31+
expect_throws(fn() => $it->offsetGet(-1));
3732
expect_throws(fn() => $it->offsetGet('1'));
3833
expect_throws(fn() => $it->offsetGet('invalid'));
39-
expect_throws(fn() => $it->get('invalid'));
4034
expect_throws(fn() => $it[['invalid']]);
4135
expect_throws(fn() => $it->offsetUnset(PHP_INT_MAX));
4236
expect_throws(fn() => $it->offsetSet(PHP_INT_MAX,'x'));
@@ -47,8 +41,6 @@ var_dump($it->getIterator());
4741
Caught ReflectionException: Class Collections\Deque is an internal class marked as final that cannot be instantiated without invoking its constructor
4842
object(stdClass)#1 (0) {
4943
}
50-
object(stdClass)#1 (0) {
51-
}
5244
Caught OutOfBoundsException: Index out of range
5345
Caught RuntimeException: Collections\Deque does not support offsetUnset - elements must be set to null or removed by resizing
5446
object(stdClass)#1 (0) {
@@ -66,15 +58,10 @@ Caught OutOfBoundsException: Index out of range
6658
Caught OutOfBoundsException: Index out of range
6759
Caught OutOfBoundsException: Index out of range
6860
Caught OutOfBoundsException: Index out of range
69-
Caught OutOfBoundsException: Index out of range
70-
Caught OutOfBoundsException: Index out of range
71-
Caught OutOfBoundsException: Index out of range
72-
Caught OutOfBoundsException: Index out of range
7361
Caught TypeError: Illegal offset type
74-
Caught TypeError: Collections\Deque::get(): Argument #1 ($offset) must be of type int, string given
7562
Caught TypeError: Illegal offset type
7663
Caught RuntimeException: Collections\Deque does not support offsetUnset - elements must be set to null or removed by resizing
7764
Caught OutOfBoundsException: Index out of range
7865
Caught RuntimeException: Collections\Deque does not support offsetUnset - elements must be set to null or removed by resizing
79-
object(InternalIterator)#2 (0) {
66+
object(InternalIterator)#4 (0) {
8067
}

ext/collections/tests/Deque/setValueAt.phpt renamed to ext/collections/tests/Deque/offsetSet.phpt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ function expect_throws(Closure $cb): void {
1515
echo "Test empty deque\n";
1616
$it = new Collections\Deque([]);
1717
expect_throws(fn() => $it->offsetSet(0, strtoupper('value')));
18-
expect_throws(fn() => $it->set(0, strtoupper('value')));
1918

2019
echo "Test short deque\n";
2120
$str = 'Test short deque';
2221
$it = new Collections\Deque(explode(' ', $str));
23-
$it->set(0, 'new');
22+
$it->offsetSet(0, 'new');
2423
$it->offsetSet(2, strtoupper('test'));
2524
echo json_encode($it), "\n";
26-
expect_throws(fn() => $it->set(-1, strtoupper('value')));
27-
expect_throws(fn() => $it->set(3, 'end'));
28-
expect_throws(fn() => $it->set(PHP_INT_MAX, 'end'));
25+
expect_throws(fn() => $it->offsetSet(-1, strtoupper('value')));
26+
expect_throws(fn() => $it->offsetSet(3, 'end'));
27+
expect_throws(fn() => $it->offsetSet(PHP_INT_MAX, 'end'));
2928

3029
?>
3130
--EXPECT--
3231
Test empty deque
3332
Caught OutOfBoundsException: Index out of range
34-
Caught OutOfBoundsException: Index out of range
3533
Test short deque
3634
["new","short","TEST"]
3735
Caught OutOfBoundsException: Index out of range

0 commit comments

Comments
 (0)