IteratorNode::__toString()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
/**
3
 * This file is part of graze/data-node
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-node/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-node
12
 */
13
14
namespace Graze\DataNode;
15
16
use ArrayIterator;
17
use CallbackFilterIterator;
18
use Iterator;
19
use IteratorIterator;
20
use Traversable;
21
22
class IteratorNode extends IteratorIterator implements IteratorNodeInterface
23
{
24
    /**
25
     * IteratorNode constructor.
26
     *
27
     * @param array|Traversable $source
28
     */
29 8
    public function __construct($source)
30
    {
31 8
        $iterator = is_array($source) ? new ArrayIterator($source) : $source;
32 8
        parent::__construct($iterator);
33 8
    }
34
35
    /**
36
     * @param callable|null $filter
37
     *
38
     * @return Iterator
39
     */
40 2
    public function fetch(callable $filter = null)
41
    {
42 2
        if ($filter) {
43 1
            return new CallbackFilterIterator($this, $filter);
44
        }
45 1
        return $this;
46
    }
47
48
    /**
49
     * @return string
50
     */
51 1
    public function __toString()
52
    {
53 1
        return __CLASS__;
54
    }
55
56
    /**
57
     * Return a clone of this object
58
     *
59
     * @note This will traverse the current iterator source to produce a clone, potentially moving past the point
60
     *       required
61
     *
62
     * @return static
63
     */
64 1
    public function getClone()
65
    {
66 1
        return new IteratorNode(iterator_to_array($this));
67
    }
68
}
69