Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of phpunit/php-code-coverage.
4
 *
5
 * (c) Sebastian Bergmann <sebastian@phpunit.de>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace SebastianBergmann\CodeCoverage\Node;
11
 
12
use function count;
13
use RecursiveIterator;
14
 
15
/**
16
 * @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
17
 */
18
final class Iterator implements RecursiveIterator
19
{
20
    /**
21
     * @var int
22
     */
23
    private $position;
24
 
25
    /**
26
     * @var AbstractNode[]
27
     */
28
    private $nodes;
29
 
30
    public function __construct(Directory $node)
31
    {
32
        $this->nodes = $node->children();
33
    }
34
 
35
    /**
36
     * Rewinds the Iterator to the first element.
37
     */
38
    public function rewind(): void
39
    {
40
        $this->position = 0;
41
    }
42
 
43
    /**
44
     * Checks if there is a current element after calls to rewind() or next().
45
     */
46
    public function valid(): bool
47
    {
48
        return $this->position < count($this->nodes);
49
    }
50
 
51
    /**
52
     * Returns the key of the current element.
53
     */
54
    public function key(): int
55
    {
56
        return $this->position;
57
    }
58
 
59
    /**
60
     * Returns the current element.
61
     */
62
    public function current(): ?AbstractNode
63
    {
64
        return $this->valid() ? $this->nodes[$this->position] : null;
65
    }
66
 
67
    /**
68
     * Moves forward to next element.
69
     */
70
    public function next(): void
71
    {
72
        $this->position++;
73
    }
74
 
75
    /**
76
     * Returns the sub iterator for the current element.
77
     */
78
    public function getChildren(): self
79
    {
80
        return new self($this->nodes[$this->position]);
81
    }
82
 
83
    /**
84
     * Checks whether the current element has children.
85
     */
86
    public function hasChildren(): bool
87
    {
88
        return $this->nodes[$this->position] instanceof Directory;
89
    }
90
}