| Conditions | 4 |
| Paths | 8 |
| Total Lines | 64 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 103 | protected function generateRoute(Route $route) |
||
| 104 | { |
||
| 105 | $conditions = []; |
||
| 106 | $this->conditionPrefix($route, $conditions); |
||
| 107 | $this->conditionUriRegex($route, $conditions); |
||
| 108 | $this->conditionHttps($route, $conditions); |
||
| 109 | |||
| 110 | $this->code->append( |
||
| 111 | sprintf( |
||
| 112 | 'if (%s) {', |
||
| 113 | implode(' && ', $conditions) |
||
| 114 | ) |
||
| 115 | ); |
||
| 116 | |||
| 117 | if ($route->hasMethod()) { |
||
| 118 | $this->code->append( |
||
| 119 | sprintf( |
||
| 120 | 'if (in_array($method, %s)) {', |
||
| 121 | $this->formatArray($route->getMethod()) |
||
| 122 | ) |
||
| 123 | ); |
||
| 124 | } |
||
| 125 | |||
| 126 | $this->code |
||
| 127 | ->append('return new RoutingResult(') |
||
| 128 | ->append('true,') |
||
| 129 | ->append('false,') |
||
| 130 | ->append('false,') |
||
| 131 | ->append('[],') |
||
| 132 | ->append($this->formatArray($route->getTarget()).','); |
||
| 133 | |||
| 134 | $arrays = $this->getArraysOfParameters($route); |
||
| 135 | if (count($arrays) >= 2) { |
||
| 136 | $this->code->append( |
||
| 137 | sprintf( |
||
| 138 | '$this->filterParameters(array_replace(%s))', |
||
| 139 | implode(', ', $this->getArraysOfParameters($route)) |
||
| 140 | ) |
||
| 141 | ); |
||
| 142 | } else { |
||
| 143 | $this->code->append( |
||
| 144 | sprintf( |
||
| 145 | '$this->filterParameters(%s)', |
||
| 146 | $this->getArraysOfParameters($route)[0] |
||
| 147 | ) |
||
| 148 | ); |
||
| 149 | } |
||
| 150 | |||
| 151 | $this->code->append(');'); |
||
| 152 | |||
| 153 | if ($route->hasMethod()) { |
||
| 154 | $this->code->append('}'); |
||
| 155 | $this->code->append('else {'); |
||
| 156 | $this->code->append( |
||
| 157 | sprintf( |
||
| 158 | '$allowedMethods = array_merge($allowedMethods, %s);', |
||
| 159 | $this->formatArray($route->getMethod()) |
||
| 160 | ) |
||
| 161 | ); |
||
| 162 | $this->code->append('}'); |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->code->append('}'); |
||
| 166 | } |
||
| 167 | |||
| 258 |