| Conditions | 11 |
| Paths | 56 |
| Total Lines | 45 |
| Code Lines | 30 |
| 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 |
||
| 36 | public static function renderStatic( |
||
| 37 | array $arguments, |
||
| 38 | \Closure $renderChildrenClosure, |
||
| 39 | RenderingContextInterface $renderingContext |
||
| 40 | ) { |
||
| 41 | $src = $arguments['src']; |
||
| 42 | $image = $arguments['image']; |
||
| 43 | $treatIdAsReference = $arguments['treatIdAsReference']; |
||
| 44 | $crop = $arguments['crop']; |
||
| 45 | //$absolute = $arguments['absolute']; |
||
| 46 | |||
| 47 | if (is_null($src) && is_null($image) || !is_null($src) && !is_null($image)) { |
||
| 48 | throw new Exception('You must either specify a string src or a File object.', 1382284105); |
||
| 49 | } |
||
| 50 | |||
| 51 | try { |
||
| 52 | $imageService = self::getImageService(); |
||
| 53 | $image = $imageService->getImage($src, $image, $treatIdAsReference); |
||
| 54 | |||
| 55 | if ($crop === null) { |
||
| 56 | $crop = $image instanceof FileReference ? $image->getProperty('crop') : null; |
||
| 57 | } |
||
| 58 | |||
| 59 | $processingInstructions = [ |
||
| 60 | 'width' => $arguments['width'], |
||
| 61 | 'height' => $arguments['height'], |
||
| 62 | 'minWidth' => $arguments['minWidth'], |
||
| 63 | 'minHeight' => $arguments['minHeight'], |
||
| 64 | 'maxWidth' => $arguments['maxWidth'], |
||
| 65 | 'maxHeight' => $arguments['maxHeight'], |
||
| 66 | 'crop' => $crop, |
||
| 67 | ]; |
||
| 68 | $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); |
||
| 69 | return $imageService->getImageUri($processedImage); |
||
| 70 | } catch (ResourceDoesNotExistException $e) { |
||
| 71 | // thrown if file does not exist |
||
| 72 | } catch (\UnexpectedValueException $e) { |
||
| 73 | // thrown if a file has been replaced with a folder |
||
| 74 | } catch (\RuntimeException $e) { |
||
| 75 | // RuntimeException thrown if a file is outside of a storage |
||
| 76 | } catch (\InvalidArgumentException $e) { |
||
| 77 | // thrown if file storage does not exist |
||
| 78 | } |
||
| 79 | return ''; |
||
| 80 | } |
||
| 81 | |||
| 94 |