Skip to content

Commit 5c7d77c

Browse files
committed
Address code review comments
1 parent 79dcc05 commit 5c7d77c

File tree

3 files changed

+16
-51
lines changed

3 files changed

+16
-51
lines changed

ext/spl/spl_iterators.c

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -483,11 +483,12 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
483483

484484
switch (rit_type) {
485485
case RIT_RecursiveTreeIterator: {
486-
zval caching_it_flags, *user_caching_it_flags = NULL;
486+
zval caching_it_flags;
487+
zend_long user_caching_it_flags = CIT_CATCH_GET_CHILD;
487488
mode = RIT_SELF_FIRST;
488489
flags = RTIT_BYPASS_KEY;
489490

490-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|lzl", &iterator, &flags, &user_caching_it_flags, &mode) == FAILURE) {
491+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "o|lll", &iterator, &flags, &user_caching_it_flags, &mode) == FAILURE) {
491492
RETURN_THROWS();
492493
}
493494

@@ -499,14 +500,9 @@ static void spl_recursive_it_it_construct(INTERNAL_FUNCTION_PARAMETERS, zend_cla
499500
Z_ADDREF_P(iterator);
500501
}
501502

502-
if (user_caching_it_flags) {
503-
ZVAL_COPY(&caching_it_flags, user_caching_it_flags);
504-
} else {
505-
ZVAL_LONG(&caching_it_flags, CIT_CATCH_GET_CHILD);
506-
}
503+
ZVAL_LONG(&caching_it_flags, user_caching_it_flags);
507504
spl_instantiate_arg_ex2(spl_ce_RecursiveCachingIterator, &caching_it, iterator, &caching_it_flags);
508505
zval_ptr_dtor(&caching_it_flags);
509-
510506
zval_ptr_dtor(iterator);
511507
iterator = &caching_it;
512508
break;
@@ -770,7 +766,7 @@ SPL_METHOD(RecursiveIteratorIterator, callHasChildren)
770766
}
771767

772768
if (!object->iterators) {
773-
RETURN_NULL();
769+
RETURN_FALSE;
774770
}
775771

776772
SPL_FETCH_SUB_ELEMENT(ce, object, ce);
@@ -1434,10 +1430,10 @@ static spl_dual_it_object* spl_dual_it_construct(INTERNAL_FUNCTION_PARAMETERS, z
14341430
break;
14351431
}
14361432
case DIT_AppendIterator:
1437-
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
14381433
if (zend_parse_parameters_none() == FAILURE) {
14391434
return NULL;
14401435
}
1436+
zend_replace_error_handling(EH_THROW, spl_ce_InvalidArgumentException, &error_handling);
14411437
spl_instantiate(spl_ce_ArrayIterator, &intern->u.append.zarrayit);
14421438
zend_call_method_with_0_params(Z_OBJ(intern->u.append.zarrayit), spl_ce_ArrayIterator, &spl_ce_ArrayIterator->constructor, "__construct", NULL);
14431439
intern->u.append.iterator = spl_ce_ArrayIterator->get_iterator(spl_ce_ArrayIterator, &intern->u.append.zarrayit, 0);

ext/spl/spl_iterators.stub.php

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function next() {}
6969
/** @return int */
7070
public function getDepth() {}
7171

72-
/** @return RecursiveIterator */
72+
/** @return RecursiveIterator|null */
7373
public function getSubIterator(int $level = UNKNOWN) {}
7474

7575
/** @return RecursiveIterator */
@@ -81,7 +81,7 @@ public function beginIteration() {}
8181
/** @return void */
8282
public function endIteration() {}
8383

84-
/** @return bool|null */
84+
/** @return bool */
8585
public function callHasChildren() {}
8686

8787
/** @return RecursiveIterator|null */
@@ -282,24 +282,6 @@ class RecursiveCachingIterator extends CachingIterator implements RecursiveItera
282282
{
283283
public function __construct(Iterator $iterator, int $flags = self::CALL_TOSTRING) {}
284284

285-
/** @return void */
286-
public function rewind() {}
287-
288-
/** @return bool */
289-
public function valid() {}
290-
291-
/** @return mixed */
292-
public function key() {}
293-
294-
/** @return mixed */
295-
public function current() {}
296-
297-
/** @return void */
298-
public function next() {}
299-
300-
/** @return Iterator|null */
301-
public function getInnerIterator() {}
302-
303285
/** @return bool */
304286
public function hasChildren() {}
305287

@@ -415,23 +397,22 @@ public function getChildren() {}
415397

416398
class RecursiveTreeIterator extends RecursiveIteratorIterator
417399
{
418-
/**
419-
* @param RecursiveIterator|IteratorAggregate $iterator
420-
* @param int $caching_it_flags
421-
*/
422-
public function __construct($iterator, int $flags = self::BYPASS_KEY, $caching_it_flags = CachingIterator::CATCH_GET_CHILD,
423-
int $mode = self::SELF_FIRST) {}
400+
/** @param RecursiveIterator|IteratorAggregate $iterator */
401+
public function __construct(
402+
$iterator, int $flags = self::BYPASS_KEY, int $caching_it_flags = CachingIterator::CATCH_GET_CHILD,
403+
int $mode = self::SELF_FIRST
404+
) {}
424405

425406
/** @return void */
426407
public function rewind() {}
427408

428409
/** @return bool */
429410
public function valid() {}
430411

431-
/** @return string */
412+
/** @return mixed */
432413
public function key() {}
433414

434-
/** @return string|null */
415+
/** @return mixed */
435416
public function current() {}
436417

437418
/** @return void */

ext/spl/spl_iterators_arginfo.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,6 @@ ZEND_END_ARG_INFO()
197197

198198
#define arginfo_class_RecursiveCachingIterator___construct arginfo_class_CachingIterator___construct
199199

200-
#define arginfo_class_RecursiveCachingIterator_rewind arginfo_class_EmptyIterator_current
201-
202-
#define arginfo_class_RecursiveCachingIterator_valid arginfo_class_EmptyIterator_current
203-
204-
#define arginfo_class_RecursiveCachingIterator_key arginfo_class_EmptyIterator_current
205-
206-
#define arginfo_class_RecursiveCachingIterator_current arginfo_class_EmptyIterator_current
207-
208-
#define arginfo_class_RecursiveCachingIterator_next arginfo_class_EmptyIterator_current
209-
210-
#define arginfo_class_RecursiveCachingIterator_getInnerIterator arginfo_class_EmptyIterator_current
211-
212200
#define arginfo_class_RecursiveCachingIterator_hasChildren arginfo_class_EmptyIterator_current
213201

214202
#define arginfo_class_RecursiveCachingIterator_getChildren arginfo_class_EmptyIterator_current
@@ -296,7 +284,7 @@ ZEND_END_ARG_INFO()
296284
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_RecursiveTreeIterator___construct, 0, 0, 1)
297285
ZEND_ARG_INFO(0, iterator)
298286
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
299-
ZEND_ARG_INFO(0, caching_it_flags)
287+
ZEND_ARG_TYPE_INFO(0, caching_it_flags, IS_LONG, 0)
300288
ZEND_ARG_TYPE_INFO(0, mode, IS_LONG, 0)
301289
ZEND_END_ARG_INFO()
302290

0 commit comments

Comments
 (0)