Conditions | 8 |
Paths | 38 |
Total Lines | 54 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
130 | public function filterRuntimeAction(Request $request, $hash, $path, $filter) |
||
131 | { |
||
132 | $resolver = $request->get('resolver'); |
||
133 | |||
134 | try { |
||
135 | $filters = $request->query->get('filters', array()); |
||
136 | |||
137 | if (!is_array($filters)) { |
||
138 | throw new NotFoundHttpException(sprintf('Filters must be an array. Value was "%s"', $filters)); |
||
139 | } |
||
140 | |||
141 | if (true !== $this->signer->check($hash, $path, $filters)) { |
||
142 | throw new BadRequestHttpException(sprintf( |
||
143 | 'Signed url does not pass the sign check for path "%s" and filter "%s" and runtime config %s', |
||
144 | $path, |
||
145 | $filter, |
||
146 | json_encode($filters) |
||
147 | )); |
||
148 | } |
||
149 | |||
150 | try { |
||
151 | $binary = $this->dataManager->find($filter, $path); |
||
152 | } catch (NotLoadableException $e) { |
||
153 | if ($defaultImageUrl = $this->dataManager->getDefaultImageUrl($filter)) { |
||
154 | return new RedirectResponse($defaultImageUrl); |
||
155 | } |
||
156 | |||
157 | throw new NotFoundHttpException(sprintf('Source image could not be found for path "%s" and filter "%s"', $path, $filter), $e); |
||
158 | } |
||
159 | |||
160 | $rcPath = $this->cacheManager->getRuntimePath($path, $filters); |
||
161 | |||
162 | $this->cacheManager->store( |
||
163 | $this->filterManager->applyFilter($binary, $filter, array( |
||
164 | 'filters' => $filters, |
||
165 | )), |
||
166 | $rcPath, |
||
167 | $filter, |
||
168 | $resolver |
||
169 | ); |
||
170 | |||
171 | return new RedirectResponse($this->cacheManager->resolve($rcPath, $filter, $resolver), 301); |
||
172 | } catch (NonExistingFilterException $e) { |
||
173 | $message = sprintf('Could not locate filter "%s" for path "%s". Message was "%s"', $filter, $hash.'/'.$path, $e->getMessage()); |
||
174 | |||
175 | if (null !== $this->logger) { |
||
176 | $this->logger->debug($message); |
||
177 | } |
||
178 | |||
179 | throw new NotFoundHttpException($message, $e); |
||
180 | } catch (RuntimeException $e) { |
||
181 | throw new \RuntimeException(sprintf('Unable to create image for path "%s" and filter "%s". Message was "%s"', $hash.'/'.$path, $filter, $e->getMessage()), 0, $e); |
||
182 | } |
||
183 | } |
||
184 | } |
||
185 |