| Conditions | 9 |
| Paths | 48 |
| Total Lines | 53 |
| 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 |
||
| 44 | public function cropImage(EditableMediaWrapper $editableMediaWrapper, string $view = '', string $filter = 'optim'): string |
||
| 45 | { |
||
| 46 | $media = $editableMediaWrapper->getMedia(); |
||
| 47 | $path = $media->getUrl(); |
||
| 48 | $path = str_replace('://', '---', $path); |
||
| 49 | |||
| 50 | $runTimeConfigForView = []; |
||
| 51 | if ($editableMediaWrapper->getRunTimeConfig() !== null) { |
||
| 52 | $runTimeConfig = json_decode($editableMediaWrapper->getRunTimeConfig(), true); |
||
| 53 | |||
| 54 | if ( |
||
| 55 | is_array($runTimeConfig) |
||
| 56 | && !empty($view) |
||
| 57 | && isset($runTimeConfig[$view]['start'], $runTimeConfig[$view]['size']) |
||
| 58 | ) { |
||
| 59 | $runTimeConfigForView = [ |
||
| 60 | 'crop' => [ |
||
| 61 | 'start' => $runTimeConfig[$view]['start'], |
||
| 62 | 'size' => $runTimeConfig[$view]['size'], |
||
| 63 | ], |
||
| 64 | ]; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | try { |
||
| 69 | $filterConfig = $this->filterConfiguration->get($filter); |
||
| 70 | } catch (NonExistingFilterException $exception) { |
||
| 71 | $filterConfig = $this->filterConfiguration->get('optim'); |
||
| 72 | } |
||
| 73 | |||
| 74 | $oemConfig = null; |
||
| 75 | if (isset($filterConfig['filters'])) { |
||
| 76 | $oemConfig = $filterConfig; |
||
| 77 | unset($filterConfig['filters']['crop']); |
||
| 78 | $runTimeConfigForView = array_merge_recursive($runTimeConfigForView, $filterConfig['filters']); |
||
| 79 | unset($filterConfig['filters']); |
||
| 80 | $this->filterConfiguration->set($filter, $filterConfig); |
||
| 81 | } |
||
| 82 | |||
| 83 | try { |
||
| 84 | $response = $this->filterService->getUrlOfFilteredImageWithRuntimeFilters($path, $filter, $runTimeConfigForView); |
||
| 85 | } catch (\Exception $exception) { |
||
| 86 | $runTimeConfigForView = []; |
||
| 87 | |||
| 88 | $response = $this->filterService->getUrlOfFilteredImageWithRuntimeFilters($path, 'optim', $runTimeConfigForView); |
||
| 89 | } |
||
| 90 | |||
| 91 | if ($oemConfig !== null) { |
||
| 92 | $this->filterConfiguration->set($filter, $oemConfig); |
||
| 93 | } |
||
| 94 | |||
| 95 | return $response; |
||
| 96 | } |
||
| 97 | } |
||
| 98 |