| Conditions | 18 |
| Paths | 4099 |
| Total Lines | 76 |
| Code Lines | 51 |
| 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 |
||
| 17 | public function hashToFieldValue($fieldValue, array $context = array()) |
||
| 18 | { |
||
| 19 | $fileName = ''; |
||
| 20 | $mimeType = ''; |
||
| 21 | $hasController = false; |
||
| 22 | $autoPlay = false; |
||
| 23 | $loop = false; |
||
| 24 | $height = 0; |
||
| 25 | $width = 0; |
||
| 26 | |||
| 27 | if ($fieldValue === null) { |
||
| 28 | return new MediaValue(); |
||
| 29 | } else if (is_string($fieldValue)) { |
||
| 30 | $filePath = $fieldValue; |
||
| 31 | } else { |
||
| 32 | // BC |
||
| 33 | if (isset($fieldValue['fileName'])) { |
||
| 34 | $fileName = $fieldValue['fileName']; |
||
| 35 | } |
||
| 36 | if (isset($fieldValue['mimeType'])) { |
||
| 37 | $fileName = $fieldValue['mimeType']; |
||
| 38 | } |
||
| 39 | if (isset($fieldValue['hasController'])) { |
||
| 40 | $hasController = $fieldValue['hasController']; |
||
| 41 | } |
||
| 42 | if (isset($fieldValue['inputUri'])) { |
||
| 43 | $filePath = $fieldValue['inputUri']; |
||
| 44 | } else { |
||
| 45 | $filePath = $fieldValue['path']; |
||
| 46 | } |
||
| 47 | // new attribute names |
||
| 48 | if (isset($fieldValue['filename'])) { |
||
| 49 | $fileName = $fieldValue['filename']; |
||
| 50 | } |
||
| 51 | if (isset($fieldValue['has_controller'])) { |
||
| 52 | $hasController = $fieldValue['has_controller']; |
||
| 53 | } |
||
| 54 | if (isset($fieldValue['autoplay'])) { |
||
| 55 | $autoPlay = $fieldValue['autoplay']; |
||
| 56 | } |
||
| 57 | if (isset($fieldValue['loop'])) { |
||
| 58 | $loop = $fieldValue['loop']; |
||
| 59 | } |
||
| 60 | if (isset($fieldValue['height'])) { |
||
| 61 | $height = $fieldValue['height']; |
||
| 62 | } |
||
| 63 | if (isset($fieldValue['width'])) { |
||
| 64 | $width = $fieldValue['width']; |
||
| 65 | } |
||
| 66 | if (isset($fieldValue['mime_type'])) { |
||
| 67 | $mimeType = $fieldValue['mime_type']; |
||
| 68 | } |
||
| 69 | } |
||
| 70 | |||
| 71 | // 'default' format: path is relative to the 'media' dir |
||
| 72 | $realFilePath = dirname($context['path']) . '/media/' . $filePath; |
||
| 73 | |||
| 74 | // but in the past, when using a string, this worked as well as an absolute path, so we have to support it as well |
||
| 75 | if (!is_file($realFilePath) && is_file($filePath)) { |
||
| 76 | $realFilePath = $filePath; |
||
| 77 | } |
||
| 78 | |||
| 79 | return new MediaValue( |
||
| 80 | array( |
||
| 81 | 'path' => $realFilePath, |
||
| 82 | 'fileSize' => filesize($realFilePath), |
||
| 83 | 'fileName' => $fileName != '' ? $fileName : basename($realFilePath), |
||
| 84 | 'mimeType' => $mimeType != '' ? $mimeType : mime_content_type($realFilePath), |
||
| 85 | 'hasController' => $hasController, |
||
| 86 | 'autoplay' => $autoPlay, |
||
| 87 | 'loop'=> $loop, |
||
| 88 | 'height' => $height, |
||
| 89 | 'width' => $width, |
||
| 90 | ) |
||
| 91 | ); |
||
| 92 | } |
||
| 93 | |||
| 115 |