| Conditions | 12 |
| Paths | 513 |
| Total Lines | 89 |
| Code Lines | 53 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 69 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 70 | { |
||
| 71 | if (\count($input->getOption('waypoint')) < 2) { |
||
|
|
|||
| 72 | throw new InvalidArgumentException('A route needs at least two waypoints (start and end locations).'); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($input->getOption('provider')) { |
||
| 76 | $this->manager->using($input->getOption('provider')); |
||
| 77 | } |
||
| 78 | |||
| 79 | $query = $this->manager->createRoutingQuery(); |
||
| 80 | |||
| 81 | foreach ($input->getOption('waypoint') as $waypoint) { |
||
| 82 | $query->addWaypoint($waypoint); |
||
| 83 | } |
||
| 84 | |||
| 85 | if ($input->getOption('departure')) { |
||
| 86 | $query->setDepartureTime(new \DateTime($input->getOption('departure'))); |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($input->getOption('arrival')) { |
||
| 90 | $query->setArrivalTime(new \DateTime($input->getOption('arrival'))); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ($input->getOption('traffic')) { |
||
| 94 | $query->setTrafficMode($input->getOption('traffic')); |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($input->getOption('language')) { |
||
| 98 | $query->setLanguage($input->getOption('language')); |
||
| 99 | } |
||
| 100 | |||
| 101 | $response = $query->execute(); |
||
| 102 | |||
| 103 | $io = new SymfonyStyle($input, $output); |
||
| 104 | |||
| 105 | $routes = $response->getRoutes(); |
||
| 106 | |||
| 107 | $io->section('Summary'); |
||
| 108 | |||
| 109 | $data = []; |
||
| 110 | foreach ($routes as $index => $route) { |
||
| 111 | /** |
||
| 112 | * @var Summary $summary |
||
| 113 | */ |
||
| 114 | $summary = $route->getSummary(); |
||
| 115 | $data[] = [ |
||
| 116 | $index + 1, |
||
| 117 | $summary->getDistance()->getFormattedValue(2), |
||
| 118 | $summary->getTravelTime()->getFormattedValue(2), |
||
| 119 | ]; |
||
| 120 | } |
||
| 121 | |||
| 122 | $table = new Table($output); |
||
| 123 | $table |
||
| 124 | ->setHeaders(['route', 'distance', 'duration']) |
||
| 125 | ->setRows($data) |
||
| 126 | ; |
||
| 127 | $table->render(); |
||
| 128 | |||
| 129 | $io->newLine(); |
||
| 130 | |||
| 131 | foreach ($routes as $routeIndex => $route) { |
||
| 132 | $io->section('Route #'.($routeIndex + 1)); |
||
| 133 | |||
| 134 | $legs = $route->getLegs(); |
||
| 135 | foreach ($legs as $legIndex => $leg) { |
||
| 136 | $steps = $leg->getSteps(); |
||
| 137 | $io->writeln(sprintf('<comment>Leg #%d</comment> - %d steps.', $legIndex + 1, \count($steps))); |
||
| 138 | |||
| 139 | $data = []; |
||
| 140 | foreach ($steps as $stepIndex => $step) { |
||
| 141 | $data[] = [ |
||
| 142 | $stepIndex + 1, |
||
| 143 | implode(', ', $step->getPosition()), |
||
| 144 | $step->getDistance()->getFormattedValue(2), |
||
| 145 | $step->getDuration()->getFormattedValue(2), |
||
| 146 | $step->getInstruction() |
||
| 147 | ]; |
||
| 148 | } |
||
| 149 | |||
| 150 | $table = new Table($output); |
||
| 151 | $table |
||
| 152 | ->setHeaders(['step', 'position', 'distance', 'duration', 'instruction']) |
||
| 153 | ->setRows($data) |
||
| 154 | ->setColumnMaxWidth(4, 100) |
||
| 155 | ; |
||
| 156 | $table->render(); |
||
| 157 | $io->newLine(); |
||
| 158 | } |
||
| 189 |