| Conditions | 3 |
| Paths | 2 |
| Total Lines | 69 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 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 | private function routeToTransitPath(array $route): TransitPathDto |
||
| 66 | { |
||
| 67 | $edges = array(); |
||
| 68 | |||
| 69 | $loadDay = \rand(1,4); |
||
| 70 | |||
| 71 | $loadTimestamp = strtotime("+$loadDay day"); |
||
| 72 | |||
| 73 | $loadTime = new \DateTime(); |
||
| 74 | $loadTime->setTimestamp($loadTimestamp); |
||
| 75 | |||
| 76 | $elapsedDays = 0; |
||
| 77 | |||
| 78 | $currentLocation = $route['origin']; |
||
| 79 | $currentTime = $loadTime; |
||
| 80 | |||
| 81 | if (!empty($route['stops'])) { |
||
| 82 | foreach($route['stops'] as $unLocode => $duration) { |
||
| 83 | $elapsedDays += $duration; |
||
| 84 | |||
| 85 | $durationInterval = new \DateInterval('P' . $duration . 'DT' . \rand(1, 12) . 'H' . \rand(1, 60) . 'M'); |
||
| 86 | |||
| 87 | $currentTime->add(new \DateInterval('P1DT' . \rand(1, 12) . 'H' . \rand(1, 60) . 'M')); |
||
| 88 | |||
| 89 | $loadTime = clone $currentTime; |
||
| 90 | |||
| 91 | $currentTime->add($durationInterval); |
||
| 92 | |||
| 93 | $unloadTime = clone $currentTime; |
||
| 94 | |||
| 95 | $edge = new EdgeDto(); |
||
| 96 | |||
| 97 | $edge->setFromUnLocode($currentLocation); |
||
| 98 | $edge->setToUnLocode($unLocode); |
||
| 99 | $edge->setFromDate($loadTime->format(\DateTime::ATOM)); |
||
| 100 | $edge->setToDate($unloadTime->format(\DateTime::ATOM)); |
||
| 101 | |||
| 102 | $edges[] = $edge; |
||
| 103 | |||
| 104 | $currentLocation = $unLocode; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $destinationDuration = $route['duration'] - $elapsedDays; |
||
| 109 | $durationInterval = new \DateInterval('P' . $destinationDuration . 'DT' . \rand(1, 12) . 'H' . \rand(1, 60) . 'M'); |
||
| 110 | |||
| 111 | $currentTime->add(new \DateInterval('P1DT' . \rand(1, 12) . 'H' . \rand(1, 60) . 'M')); |
||
| 112 | |||
| 113 | $loadTime = clone $currentTime; |
||
| 114 | |||
| 115 | $currentTime->add($durationInterval); |
||
| 116 | |||
| 117 | $unloadTime = clone $currentTime; |
||
| 118 | |||
| 119 | $edge = new EdgeDto(); |
||
| 120 | |||
| 121 | $edge->setFromUnLocode($currentLocation); |
||
| 122 | $edge->setToUnLocode($route['destination']); |
||
| 123 | $edge->setFromDate($loadTime->format(\DateTime::ATOM)); |
||
| 124 | $edge->setToDate($unloadTime->format(\DateTime::ATOM)); |
||
| 125 | |||
| 126 | $edges[] = $edge; |
||
| 127 | |||
| 128 | $transitPath = new TransitPathDto(); |
||
| 129 | |||
| 130 | $transitPath->setEdges($edges); |
||
| 131 | |||
| 132 | return $transitPath; |
||
| 133 | } |
||
| 134 | } |
||
| 135 |