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