Skip to content

Commit f4c1c4c

Browse files
committed
Remove get()/set() helpers, switch tests to offsetGet/offsetSet
1 parent 7c87abc commit f4c1c4c

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
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 7724c400fc239aace1ab5666df575d7ab2214d4f */
2+
* Stub hash: 45133ac6c134170e67c0b2dadef7c8be8b540608 */
33

44
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Collections_Deque___construct, 0, 0, 0)
55
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, iterator, IS_ITERABLE, 0, "[]")
@@ -45,15 +45,6 @@ ZEND_END_ARG_INFO()
4545

4646
#define arginfo_class_Collections_Deque_toArray arginfo_class_Collections_Deque___serialize
4747

48-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_get, 0, 1, IS_MIXED, 0)
49-
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
50-
ZEND_END_ARG_INFO()
51-
52-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_set, 0, 2, IS_VOID, 0)
53-
ZEND_ARG_TYPE_INFO(0, offset, IS_LONG, 0)
54-
ZEND_ARG_TYPE_INFO(0, value, IS_MIXED, 0)
55-
ZEND_END_ARG_INFO()
56-
5748
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Collections_Deque_offsetGet, 0, 1, IS_MIXED, 0)
5849
ZEND_ARG_TYPE_INFO(0, offset, IS_MIXED, 0)
5950
ZEND_END_ARG_INFO()
@@ -89,8 +80,6 @@ ZEND_METHOD(Collections_Deque, shift);
8980
ZEND_METHOD(Collections_Deque, bottom);
9081
ZEND_METHOD(Collections_Deque, top);
9182
ZEND_METHOD(Collections_Deque, toArray);
92-
ZEND_METHOD(Collections_Deque, get);
93-
ZEND_METHOD(Collections_Deque, set);
9483
ZEND_METHOD(Collections_Deque, offsetGet);
9584
ZEND_METHOD(Collections_Deque, offsetExists);
9685
ZEND_METHOD(Collections_Deque, offsetSet);
@@ -114,8 +103,6 @@ static const zend_function_entry class_Collections_Deque_methods[] = {
114103
ZEND_ME(Collections_Deque, bottom, arginfo_class_Collections_Deque_bottom, ZEND_ACC_PUBLIC)
115104
ZEND_ME(Collections_Deque, top, arginfo_class_Collections_Deque_top, ZEND_ACC_PUBLIC)
116105
ZEND_ME(Collections_Deque, toArray, arginfo_class_Collections_Deque_toArray, ZEND_ACC_PUBLIC)
117-
ZEND_ME(Collections_Deque, get, arginfo_class_Collections_Deque_get, ZEND_ACC_PUBLIC)
118-
ZEND_ME(Collections_Deque, set, arginfo_class_Collections_Deque_set, ZEND_ACC_PUBLIC)
119106
ZEND_ME(Collections_Deque, offsetGet, arginfo_class_Collections_Deque_offsetGet, ZEND_ACC_PUBLIC)
120107
ZEND_ME(Collections_Deque, offsetExists, arginfo_class_Collections_Deque_offsetExists, ZEND_ACC_PUBLIC)
121108
ZEND_ME(Collections_Deque, offsetSet, arginfo_class_Collections_Deque_offsetSet, ZEND_ACC_PUBLIC)

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)