| Conditions | 6 |
| Paths | 6 |
| Total Lines | 53 |
| Code Lines | 18 |
| 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 |
||
| 45 | protected function mediaRequest(array $requests, MediaField $field, Request $request): MediaRequest |
||
|
|
|||
| 46 | { |
||
| 47 | $mediaRequest = new MediaRequest(); |
||
| 48 | |||
| 49 | foreach ($requests as $requestData) { |
||
| 50 | foreach ($requestData as $locale => $values) { |
||
| 51 | foreach ($values as $key => $value) { |
||
| 52 | |||
| 53 | // The null entries in the 'replace' request are passed explicitly - the replace array contains all existing assets (ids as keys, null as value) |
||
| 54 | if (is_null($value)) { |
||
| 55 | $mediaRequest->add(MediaRequest::DETACH, new MediaRequestInput( |
||
| 56 | '', $locale, $field->getKey(), [ |
||
| 57 | 'existing_id' => $key, |
||
| 58 | 'value_as_assetid' => true, |
||
| 59 | ] |
||
| 60 | )); |
||
| 61 | |||
| 62 | continue; |
||
| 63 | } |
||
| 64 | |||
| 65 | $action = $this->looksLikeAnAssetID($key) |
||
| 66 | ? MediaRequest::REPLACE |
||
| 67 | : MediaRequest::NEW; |
||
| 68 | |||
| 69 | // // If the value is the same as the original key and the asset already exists, we'll ignore this request. |
||
| 70 | // if($key == $value && $keyRefersToExistingAsset && $valueRefersToExistingAsset) { |
||
| 71 | // continue; |
||
| 72 | // } |
||
| 73 | |||
| 74 | $mediaRequest->add($action, new MediaRequestInput( |
||
| 75 | $value, $locale, $field->getKey(), [ |
||
| 76 | 'existing_id' => $key, |
||
| 77 | 'value_as_assetid' => $this->looksLikeAnAssetID($value), // index key is used for replace method to indicate the current asset id |
||
| 78 | ] |
||
| 79 | )); |
||
| 80 | |||
| 81 | // // Slim can push the ajax response object as value so we'll need to extract the id from this object |
||
| 82 | // if(is_string($file) && ($slimPayload = json_decode($file)) && isset($slimPayload->id)) { |
||
| 83 | // $file = $slimPayload->id; |
||
| 84 | // } |
||
| 85 | |||
| 86 | // $mediaRequest->add($action, new MediaRequestInput( |
||
| 87 | // $file, $locale, $field->getKey(), [ |
||
| 88 | // 'index' => $k, |
||
| 89 | // // index key is used for replace method to indicate the current asset id |
||
| 90 | // 'value_as_assetid' => $this->refersToExistingAsset($file), |
||
| 91 | // ] |
||
| 92 | // )); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | } |
||
| 96 | |||
| 97 | return $mediaRequest; |
||
| 98 | } |
||
| 178 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.