| Conditions | 15 |
| Paths | 88 |
| Total Lines | 56 |
| 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 |
||
| 132 | public function prepare(Request $request) |
||
| 133 | { |
||
| 134 | $this->headers->set('Content-Length', $this->file->size); |
||
| 135 | $this->headers->set('Accept-Ranges', 'bytes'); |
||
| 136 | $this->headers->set('Content-Transfer-Encoding', 'binary'); |
||
| 137 | |||
| 138 | if (!$this->headers->has('Content-Type')) { |
||
| 139 | $this->headers->set( |
||
| 140 | 'Content-Type', |
||
| 141 | $this->ioService->getMimeType($this->file->id) ?: 'application/octet-stream' |
||
| 142 | ); |
||
| 143 | } |
||
| 144 | |||
| 145 | if ('HTTP/1.0' != $request->server->get('SERVER_PROTOCOL')) { |
||
| 146 | $this->setProtocolVersion('1.1'); |
||
| 147 | } |
||
| 148 | |||
| 149 | $this->ensureIEOverSSLCompatibility($request); |
||
| 150 | |||
| 151 | $this->offset = 0; |
||
| 152 | $this->maxlen = -1; |
||
| 153 | |||
| 154 | if ($request->headers->has('Range')) { |
||
| 155 | // Process the range headers. |
||
| 156 | if (!$request->headers->has('If-Range') || $this->getEtag() == $request->headers->get('If-Range')) { |
||
| 157 | $range = $request->headers->get('Range'); |
||
| 158 | $fileSize = $this->file->size; |
||
| 159 | |||
| 160 | list($start, $end) = explode('-', substr($range, 6), 2) + [0]; |
||
| 161 | |||
| 162 | $end = ('' === $end) ? $fileSize - 1 : (int)$end; |
||
| 163 | |||
| 164 | if ('' === $start) { |
||
| 165 | $start = $fileSize - $end; |
||
| 166 | $end = $fileSize - 1; |
||
| 167 | } else { |
||
| 168 | $start = (int)$start; |
||
| 169 | } |
||
| 170 | |||
| 171 | if ($start <= $end) { |
||
| 172 | if ($start < 0 || $end > $fileSize - 1) { |
||
| 173 | $this->setStatusCode(416); // HTTP_REQUESTED_RANGE_NOT_SATISFIABLE |
||
| 174 | } elseif ($start !== 0 || $end !== $fileSize - 1) { |
||
| 175 | $this->maxlen = $end < $fileSize ? $end - $start + 1 : -1; |
||
| 176 | $this->offset = $start; |
||
| 177 | |||
| 178 | $this->setStatusCode(206); // HTTP_PARTIAL_CONTENT |
||
| 179 | $this->headers->set('Content-Range', sprintf('bytes %s-%s/%s', $start, $end, $fileSize)); |
||
| 180 | $this->headers->set('Content-Length', $end - $start + 1); |
||
| 181 | } |
||
| 182 | } |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | return $this; |
||
| 187 | } |
||
| 188 | |||
| 228 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.