Completed
Pull Request — master (#304)
by Atlas
02:28
created

GraphDeduplicated::addEdge()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 12
rs 9.4285
1
<?php
2
3
namespace Hal\Component\Tree;
4
5
class GraphDeduplicated extends Graph
6
{
7
    /**
8
     * @var array list of already present edges in this graph
9
     */
10
    private $edgesMap = [];
11
12
    /**
13
     * @param Node $from
14
     * @param Node $to
15
     *
16
     * @return $this
17
     */
18
    public function addEdge(Node $from, Node $to)
19
    {
20
        $key = $from->getUniqueId().'->'.$to->getUniqueId();
21
22
        if (isset($this->edgesMap[$key])) {
23
            return $this;
24
        }
25
26
        $this->edgesMap[$key] = true;
27
28
        return parent::addEdge($from, $to);
29
    }
30
}
31