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

HashMap   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A attach() 0 5 1
A get() 0 4 2
A has() 0 4 1
A count() 0 4 1
A getIterator() 0 4 1
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
}