| Conditions | 8 |
| Paths | 33 |
| Total Lines | 68 |
| Code Lines | 42 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 65 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 66 | { |
||
| 67 | if (\count($input->getOption('waypoint')) < 2) { |
||
|
|
|||
| 68 | throw new InvalidArgumentException('A route needs at least two waypoints (start and end locations).'); |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($input->getOption('provider')) { |
||
| 72 | $this->manager->using($input->getOption('provider')); |
||
| 73 | } |
||
| 74 | |||
| 75 | $query = $this->manager->createRoutingQuery(); |
||
| 76 | |||
| 77 | foreach ($input->getOption('waypoint') as $waypoint) { |
||
| 78 | $query->addWaypoint($waypoint); |
||
| 79 | } |
||
| 80 | $response = $query->execute(); |
||
| 81 | |||
| 82 | $io = new SymfonyStyle($input, $output); |
||
| 83 | |||
| 84 | $routes = $response->getRoutes(); |
||
| 85 | |||
| 86 | $io->section('Summary'); |
||
| 87 | |||
| 88 | $data = []; |
||
| 89 | foreach ($routes as $index => $route) { |
||
| 90 | /** |
||
| 91 | * @var Summary $summary |
||
| 92 | */ |
||
| 93 | $summary = $route->getSummary(); |
||
| 94 | $data[] = [$index + 1, $summary->getDistance()->getAsText(), $summary->getTravelTime()->getAsText()]; |
||
| 95 | } |
||
| 96 | |||
| 97 | $table = new Table($output); |
||
| 98 | $table |
||
| 99 | ->setHeaders(['route', 'distance', 'duration']) |
||
| 100 | ->setRows($data) |
||
| 101 | ; |
||
| 102 | $table->render(); |
||
| 103 | |||
| 104 | $io->newLine(); |
||
| 105 | |||
| 106 | foreach ($routes as $routeIndex => $route) { |
||
| 107 | $io->section('Route #'.($routeIndex + 1)); |
||
| 108 | |||
| 109 | $legs = $route->getLegs(); |
||
| 110 | foreach ($legs as $legIndex => $leg) { |
||
| 111 | $steps = $leg->getSteps(); |
||
| 112 | $io->writeln(sprintf('<comment>Leg #%d</comment> - %d steps.', $legIndex + 1, \count($steps))); |
||
| 113 | |||
| 114 | $data = []; |
||
| 115 | foreach ($steps as $stepIndex => $step) { |
||
| 116 | $data[] = [ |
||
| 117 | $stepIndex + 1, |
||
| 118 | implode(', ', $step->getPosition()), |
||
| 119 | $step->getDistance()->getAsText(), |
||
| 120 | $step->getDuration()->getAsText(), |
||
| 121 | $step->getInstruction() |
||
| 122 | ]; |
||
| 123 | } |
||
| 124 | |||
| 125 | $table = new Table($output); |
||
| 126 | $table |
||
| 127 | ->setHeaders(['step', 'position', 'distance', 'duration', 'instruction']) |
||
| 128 | ->setRows($data) |
||
| 129 | ->setColumnMaxWidth(4, 100) |
||
| 130 | ; |
||
| 131 | $table->render(); |
||
| 132 | $io->newLine(); |
||
| 133 | } |
||
| 164 |