1: <?php declare(strict_types=1);
2:
3: namespace Salient\Iterator\Concern;
4:
5: use Salient\Iterator\GraphIterator;
6:
7: /**
8: * Implements RecursiveIterator for GraphIterator subclasses
9: *
10: * @api
11: *
12: * @phpstan-require-extends GraphIterator
13: * @phpstan-require-implements \RecursiveIterator
14: */
15: trait RecursiveGraphIteratorTrait
16: {
17: /**
18: * @inheritDoc
19: */
20: public function hasChildren(): bool
21: {
22: /** @var GraphIterator $this */
23: $current = $this->current();
24: if ($current === false) {
25: // @codeCoverageIgnoreStart
26: return false;
27: // @codeCoverageIgnoreEnd
28: }
29:
30: return is_object($current) || is_array($current);
31: }
32:
33: /**
34: * @inheritDoc
35: */
36: public function getChildren(): ?self
37: {
38: /** @var GraphIterator $this */
39: $key = $this->key();
40: if ($key === null) {
41: // @codeCoverageIgnoreStart
42: return null;
43: // @codeCoverageIgnoreEnd
44: }
45:
46: if ($this->IsObject) {
47: $current = &$this->Graph->{$key};
48: } else {
49: // @phpstan-ignore-next-line
50: $current = &$this->Graph[$key];
51: }
52:
53: if (is_object($current) || is_array($current)) {
54: return new self($current);
55: }
56:
57: // @codeCoverageIgnoreStart
58: return null;
59: // @codeCoverageIgnoreEnd
60: }
61: }
62: