| Conditions | 4 |
| Paths | 4 |
| Total Lines | 19 |
| Code Lines | 7 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 55 | public static function numberOfSelfLoops(Graph $graph) |
||
| 56 | { |
||
| 57 | // init |
||
| 58 | $count = 0; |
||
| 59 | // get vertices |
||
| 60 | $vertices = $graph->getVertices(); |
||
| 61 | // iterate over the graph vertices |
||
| 62 | for ($vertex = 0; $vertex < $vertices; $vertex++) { |
||
| 63 | // iterate over the adjacent vertices |
||
| 64 | foreach ($graph->adjacent($vertex) as $w) { |
||
| 65 | // is this vertex adjacent to itself |
||
| 66 | if ($vertex == $w) { |
||
| 67 | // yes, bump up |
||
| 68 | $count++; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | // self loop appears in adjacency list twice |
||
| 73 | return $count/2; |
||
| 74 | } |
||
| 76 |