Total Complexity | 9 |
Total Lines | 58 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
5 | class SequencePrinter |
||
6 | { |
||
7 | /** |
||
8 | * @param Graph $graph |
||
9 | * @param iterable<Coordinate> $sequence |
||
10 | */ |
||
11 | 4 | public function __construct(private Graph $graph, private iterable $sequence) |
|
13 | 4 | } |
|
14 | |||
15 | 4 | public function printSequence(): void |
|
16 | { |
||
17 | 4 | $coordinatesAsString = []; |
|
18 | |||
19 | 4 | foreach ($this->sequence as $coordinate) { |
|
20 | 3 | $coordinatesAsString[] = $this->getCoordinateAsString($coordinate); |
|
21 | } |
||
22 | |||
23 | 4 | $cost = $this->getTotalDistance(); |
|
24 | |||
25 | 3 | if (!empty($coordinatesAsString)) { |
|
26 | 2 | echo implode(' => ', $coordinatesAsString); |
|
27 | 2 | echo "\n"; |
|
28 | } |
||
29 | |||
30 | 3 | echo "Total cost: $cost"; |
|
31 | 3 | } |
|
32 | |||
33 | 3 | private function getCoordinateAsString(Coordinate $coordinate): string |
|
36 | } |
||
37 | |||
38 | 4 | private function getTotalDistance(): float | int |
|
65 |