EWDCC   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A dfs() 0 18 3
1
<?php
2
3
namespace TemplesOfCode\NodesAndEdges\DFS;
4
5
use TemplesOfCode\NodesAndEdges\Edge;
6
7
/**
8
 * Class EWDCC
9
 * @package TemplesOfCode\NodesAndEdges
10
 */
11
class EWDCC extends ConnectedComponent
12
{
13
    /**
14
     * Depth-first search for an DirectedGraph
15
     * @param $vertex
16
     */
17
    protected function dfs(int $vertex)
18
    {
19
        // we have visited now
20
        $this->marked[$vertex] = true;
21
        // set the component #
22
        $this->id[$vertex] = $this->count;
23
        // bump up the size of this component
24
        $this->size[$this->count]++;
25
        // get the neighbors
26
        $neighbors = $this->graph->adjacent($vertex);
27
        // iterate over the neighbors
28
        foreach ($neighbors as $neighbor) {
29
            /** @var Edge $neighbor */
30
            $w = $neighbor->other($vertex);
31
            // check if we have visited this vertex
32
            if (!$this->marked[$w]) {
33
                // we have not, lets visit with dfs
34
                $this->dfs($w);
35
            }
36
        }
37
    }
38
}
39