FormViewIterator::hasChildren()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\AdminBundle\Util;
15
16
use Symfony\Component\Form\FormView;
17
18
/**
19
 * @author Thomas Rabaix <[email protected]>
20
 */
21
final class FormViewIterator implements \RecursiveIterator
22
{
23
    /**
24
     * @var \ArrayIterator<string, FormView>
25
     */
26
    private $iterator;
27
28
    public function __construct(FormView $formView)
29
    {
30
        $this->iterator = $formView->getIterator();
31
    }
32
33
    public function getChildren()
34
    {
35
        return new self($this->current());
36
    }
37
38
    public function hasChildren()
39
    {
40
        return \count($this->current()->children) > 0;
41
    }
42
43
    public function current()
44
    {
45
        return $this->iterator->current();
46
    }
47
48
    public function next(): void
49
    {
50
        $this->iterator->next();
51
    }
52
53
    public function key()
54
    {
55
        return $this->current()->vars['id'];
56
    }
57
58
    public function valid()
59
    {
60
        return $this->iterator->valid();
61
    }
62
63
    public function rewind(): void
64
    {
65
        $this->iterator->rewind();
66
    }
67
}
68