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

GraphDeduplicated   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
rs 10
wmc 2
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A addEdge() 0 12 2
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