Completed
Push — master ( bdaaad...4f4372 )
by personal
04:35 queued 45s
created

HashMap::count()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * (c) Jean-François Lépine <https://twitter.com/Halleck45>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Hal\Component\Tree;
11
12
13
class HashMap implements \Countable, \IteratorAggregate
14
{
15
    /**
16
     * @var array
17
     */
18
    private $nodes = array();
19
20
    /**
21
     * @param Node $node
22
     * @return $this
23
     */
24
    public function attach(Node $node)
25
    {
26
        $this->nodes[$node->getKey()] = $node;
27
        return $this;
28
    }
29
30
    /**
31
     * @param $key
32
     * @return Node
33
     */
34
    public function get($key)
35
    {
36
        return $this->has($key) ? $this->nodes[$key] : null;
37
    }
38
39
    /**
40
     * @param $key
41
     * @return bool
42
     */
43
    public function has($key)
44
    {
45
        return isset($this->nodes[$key]);
46
    }
47
48
    /**
49
     * @return int
50
     */
51
    public function count()
52
    {
53
        return sizeof($this->nodes);
54
    }
55
56
    /**
57
     * @return \ArrayIterator
58
     */
59
    public function getIterator()
60
    {
61
        return new \ArrayIterator($this->nodes);
62
    }
63
}