EWDCC::dfs()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 1
dl 0
loc 18
rs 10
c 0
b 0
f 0
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