Completed
Push — master ( c45521...844759 )
by stéphane
08:22
created

NodeList::hasContent()   A

Complexity

Conditions 6
Paths 3

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 7
nc 3
nop 0
dl 0
loc 10
rs 9.2222
c 0
b 0
f 0
1
<?php
2
namespace Dallgoot\Yaml;
3
4
/**
5
 * TODO
6
 *
7
 * @author  Stéphane Rebai <[email protected]>
8
 * @license Apache 2.0
9
 * @link    TODO : url to specific online doc
10
 */
11
class NodeList extends \SplDoublyLinkedList
12
{
13
    /**
14
     * NodeList constructor
15
     *
16
     * @param Node|null $node (optional) a node that will be pushed as first element
17
     */
18
    public function __construct(Node $node = null)
19
    {
20
        $this->setIteratorMode(NodeList::IT_MODE_KEEP);
21
        if (!is_null($node)) {
22
            $this->push($node);
23
        }
24
    }
25
26
    public function has(string $nodeType):bool
27
    {
28
        $tmp = clone $this;
29
        $tmp->rewind();
30
        foreach ($tmp as $child) {
31
            if (is_a($child, $nodeType)) return true;
32
        }
33
        return false;
34
    }
35
36
    public function hasContent():bool
37
    {
38
        $tmp = clone $this;
39
        $tmp->rewind();
40
        foreach ($tmp as $child) {
41
            if (!($child instanceof NodeComment)
42
                && !($child instanceof NodeDirective)
43
                && !($child instanceof NodeDocstart && is_null($child->value)) ) return true;
44
        }
45
        return false;
46
    }
47
48
    /**
49
     * Provides a slimmer output when using var_dump Note: currently PHP ignores it on SPL types
50
     * @todo activate when PHP supports it
51
     */
52
    // public function __debugInfo()
53
    // {
54
    //     return ['type'=> Y::getName($this->type), 'dllist'=> $this->dllist];
55
    // }
56
}
57