| Conditions | 17 |
| Paths | 160 |
| Total Lines | 55 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 119 | public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext) |
||
| 120 | { |
||
| 121 | $src = (string)$arguments['src']; |
||
| 122 | $image = $arguments['image']; |
||
| 123 | $treatIdAsReference = (bool)$arguments['treatIdAsReference']; |
||
| 124 | $cropString = $arguments['crop']; |
||
| 125 | $absolute = $arguments['absolute']; |
||
| 126 | |||
| 127 | if (($src === '' && $image === null) || ($src !== '' && $image !== null)) { |
||
| 128 | throw new Exception('You must either specify a string src or a File object.', 1460976233); |
||
| 129 | } |
||
| 130 | |||
| 131 | // A URL was given as src, this is kept as is |
||
| 132 | if ($src !== '' && preg_match('/^(https?:)?\/\//', $src)) { |
||
| 133 | return $src; |
||
| 134 | } |
||
| 135 | |||
| 136 | try { |
||
| 137 | $imageService = self::getImageService(); |
||
| 138 | $image = $imageService->getImage($src, $image, $treatIdAsReference); |
||
| 139 | |||
| 140 | if ($cropString === null && $image->hasProperty('crop') && $image->getProperty('crop')) { |
||
| 141 | $cropString = $image->getProperty('crop'); |
||
| 142 | } |
||
| 143 | |||
| 144 | $cropVariantCollection = CropVariantCollection::create((string)$cropString); |
||
| 145 | $cropVariant = $arguments['cropVariant'] ?: 'default'; |
||
| 146 | $cropArea = $cropVariantCollection->getCropArea($cropVariant); |
||
| 147 | $processingInstructions = [ |
||
| 148 | 'width' => $arguments['width'], |
||
| 149 | 'height' => $arguments['height'], |
||
| 150 | 'minWidth' => $arguments['minWidth'], |
||
| 151 | 'minHeight' => $arguments['minHeight'], |
||
| 152 | 'maxWidth' => $arguments['maxWidth'], |
||
| 153 | 'maxHeight' => $arguments['maxHeight'], |
||
| 154 | 'crop' => $cropArea->isEmpty() ? null : $cropArea->makeAbsoluteBasedOnFile($image), |
||
| 155 | ]; |
||
| 156 | if (!empty($arguments['fileExtension'])) { |
||
| 157 | $processingInstructions['fileExtension'] = $arguments['fileExtension']; |
||
| 158 | } |
||
| 159 | |||
| 160 | $processedImage = $imageService->applyProcessingInstructions($image, $processingInstructions); |
||
| 161 | return $imageService->getImageUri($processedImage, $absolute); |
||
| 162 | } catch (ResourceDoesNotExistException $e) { |
||
| 163 | // thrown if file does not exist |
||
| 164 | throw new Exception($e->getMessage(), 1509741907, $e); |
||
| 165 | } catch (\UnexpectedValueException $e) { |
||
| 166 | // thrown if a file has been replaced with a folder |
||
| 167 | throw new Exception($e->getMessage(), 1509741908, $e); |
||
| 168 | } catch (\RuntimeException $e) { |
||
| 169 | // RuntimeException thrown if a file is outside of a storage |
||
| 170 | throw new Exception($e->getMessage(), 1509741909, $e); |
||
| 171 | } catch (\InvalidArgumentException $e) { |
||
| 172 | // thrown if file storage does not exist |
||
| 173 | throw new Exception($e->getMessage(), 1509741910, $e); |
||
| 174 | } |
||
| 189 |