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