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