| Conditions | 4 |
| Paths | 4 |
| Total Lines | 25 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 38 | 4 | private function getTotalDistance(): float | int |
|
| 39 | { |
||
| 40 | /** @var Coordinate[] $sequence */ |
||
| 41 | 4 | $sequence = (array) $this->sequence; |
|
| 42 | |||
| 43 | 4 | if (count($sequence) < 2) { |
|
| 44 | 2 | return 0; |
|
| 45 | } |
||
| 46 | |||
| 47 | 2 | $totalDistance = 0; |
|
| 48 | |||
| 49 | 2 | $previousNode = array_shift($sequence); |
|
| 50 | 2 | foreach ($sequence as $node) { |
|
| 51 | 2 | $link = $this->graph->getLink($previousNode, $node); |
|
| 52 | |||
| 53 | 2 | if (!$link) { |
|
| 54 | 1 | throw new \RuntimeException('Some of the nodes in the provided sequence are not connected'); |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | $totalDistance += $link->getDistance(); |
|
| 58 | |||
| 59 | 2 | $previousNode = $node; |
|
| 60 | } |
||
| 61 | |||
| 62 | 1 | return $totalDistance; |
|
| 63 | } |
||
| 65 |