getCurrentResource()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/*
4
 * This file is part of the puli/repository package.
5
 *
6
 * (c) Bernhard Schussek <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Puli\Repository\Resource\Iterator;
13
14
use Puli\Repository\Api\ResourceIterator;
15
use RecursiveIteratorIterator;
16
17
/**
18
 * Iterates recursively over {@link RecursiveResourceIterator} instances.
19
 *
20
 * Use this iterator to iterate recursively over a recursive resource iterator:
21
 *
22
 * ```php
23
 * $iterator = new RecursiveResourceIteratorIterator(
24
 *     new ResourceCollectionIterator(
25
 *         $collection,
26
 *         ResourceCollectionIterator::KEY_AS_PATH | ResourceCollectionIterator::CURRENT_AS_RESOURCE
27
 *     ),
28
 *     RecursiveResourceIteratorIterator::SELF_FIRST
29
 * );
30
 *
31
 * foreach ($iterator as $path => $resource) {
32
 *     // ...
33
 * }
34
 * ```
35
 *
36
 * The configuration of this iterator works identically to its parent class
37
 * {@link RecursiveIteratorIterator}.
38
 *
39
 * @since  1.0
40
 *
41
 * @author Bernhard Schussek <[email protected]>
42
 */
43
class RecursiveResourceIteratorIterator extends RecursiveIteratorIterator implements ResourceIterator
44
{
45
    /**
46
     * Creates a new iterator.
47
     *
48
     * @param RecursiveResourceIterator $iterator The inner iterator.
49
     * @param int                       $mode     The iteration mode.
50
     * @param int                       $flags    The iteration flags.
51
     *
52
     * @see RecursiveIteratorIterator::__construct
53
     */
54 9
    public function __construct(RecursiveResourceIterator $iterator, $mode = self::LEAVES_ONLY, $flags = 0)
55
    {
56 9
        parent::__construct($iterator, $mode, $flags);
57 9
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 5
    public function getCurrentResource()
63
    {
64 5
        return $this->getInnerIterator()->getCurrentResource();
65
    }
66
}
67