| Conditions | 4 |
| Paths | 6 |
| Total Lines | 59 |
| 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 |
||
| 62 | public function getMappingAutoSuggestions() |
||
| 63 | { |
||
| 64 | $user = new User(); |
||
| 65 | $options = [ |
||
| 66 | [ |
||
| 67 | 'hint' => $user->getAttributeLabel('firstName'), |
||
| 68 | 'name' => '{firstName}', |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'hint' => $user->getAttributeLabel('lastName'), |
||
| 72 | 'name' => '{lastName}', |
||
| 73 | ], |
||
| 74 | [ |
||
| 75 | 'hint' => $user->getAttributeLabel('email'), |
||
| 76 | 'name' => '{email}', |
||
| 77 | ], |
||
| 78 | [ |
||
| 79 | 'hint' => $user->getAttributeLabel('username'), |
||
| 80 | 'name' => '{username}', |
||
| 81 | ], |
||
| 82 | [ |
||
| 83 | 'hint' => $user->getAttributeLabel('uid'), |
||
| 84 | 'name' => '{uid}', |
||
| 85 | ], |
||
| 86 | [ |
||
| 87 | 'hint' => $user->getAttributeLabel('id'), |
||
| 88 | 'name' => '{id}', |
||
| 89 | ], |
||
| 90 | ]; |
||
| 91 | |||
| 92 | $contentOptions = []; |
||
| 93 | foreach ($user->getFieldLayout()->getFields() as $field) { |
||
| 94 | if (! MappingHelper::isSupportedField($field)) { |
||
| 95 | continue; |
||
| 96 | } |
||
| 97 | |||
| 98 | $fieldType = get_class($field); |
||
| 99 | $contentOptions[] = [ |
||
| 100 | 'hint' => $field->name . " ($fieldType)", |
||
| 101 | 'name' => '{' . $field->handle . '}', |
||
| 102 | ]; |
||
| 103 | } |
||
| 104 | |||
| 105 | $return = [ |
||
| 106 | [ |
||
| 107 | 'label' => 'Standard Fields', |
||
| 108 | 'data' => $options, |
||
| 109 | ], |
||
| 110 | ]; |
||
| 111 | |||
| 112 | if (! empty($contentOptions)) { |
||
| 113 | $return[] = [ |
||
| 114 | 'label' => 'Content Fields', |
||
| 115 | 'data' => $contentOptions, |
||
| 116 | ]; |
||
| 117 | } |
||
| 118 | |||
| 119 | return $return; |
||
| 120 | } |
||
| 121 | } |
||
| 122 |