Conditions | 27 |
Paths | 27 |
Total Lines | 78 |
Code Lines | 64 |
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 |
||
205 | private function buildFieldMappings(ClassMetadata $metaData): array |
||
206 | { |
||
207 | $data = []; |
||
208 | |||
209 | foreach ($metaData->fieldMappings as $fieldMapping) { |
||
210 | switch ($fieldMapping['type']) { |
||
211 | case 'smallint': |
||
212 | case 'integer': |
||
213 | case 'bigint': |
||
214 | $data[] = sprintf( |
||
215 | " '%s' => random_int(0, 65000),\n", |
||
216 | $fieldMapping['fieldName'] |
||
217 | ); |
||
218 | break; |
||
219 | case 'decimal': |
||
220 | case 'float': |
||
221 | $data[] = sprintf( |
||
222 | " '%s' => Faker::randomFloat(2),\n", |
||
223 | $fieldMapping['fieldName'] |
||
224 | ); |
||
225 | break; |
||
226 | case 'string': |
||
227 | $data[] = sprintf( |
||
228 | " '%s' => Faker::sentence(),\n", |
||
229 | $fieldMapping['fieldName'] |
||
230 | ); |
||
231 | break; |
||
232 | case 'text': |
||
233 | $data[] = sprintf( |
||
234 | " '%s' => Faker::paragraph(),\n", |
||
235 | $fieldMapping['fieldName'] |
||
236 | ); |
||
237 | break; |
||
238 | case 'guid': |
||
239 | $data[] = sprintf( |
||
240 | " '%s' => uniqid('', true)", |
||
241 | $fieldMapping['fieldName'] |
||
242 | ); |
||
243 | break; |
||
244 | case 'binary': |
||
245 | case 'blob': |
||
246 | break; |
||
247 | case 'boolean': |
||
248 | $data[] = sprintf( |
||
249 | " '%s' => (bool)random_int(0, 1),\n", |
||
250 | $fieldMapping['fieldName'] |
||
251 | ); |
||
252 | break; |
||
253 | case 'date': |
||
254 | case 'date_immutable': |
||
255 | case 'datetime': |
||
256 | case 'datetime_immutable': |
||
257 | case 'datetimetz': |
||
258 | case 'datetimetz_immutable': |
||
259 | case 'time': |
||
260 | case 'time_immutable': |
||
261 | $data[] = sprintf( |
||
262 | " '%s' => Faker::dateTime(),\n", |
||
263 | $fieldMapping['fieldName'] |
||
264 | ); |
||
265 | break; |
||
266 | case 'dateinterval': |
||
267 | case 'array': |
||
268 | case 'simple_array': |
||
269 | case 'json': |
||
270 | case 'json_array': |
||
271 | case 'object': |
||
272 | break; |
||
273 | default: |
||
274 | $data[] = sprintf( |
||
275 | " '%s' => Faker::word(),\n", |
||
276 | $fieldMapping['fieldName'] |
||
277 | ); |
||
278 | break; |
||
279 | } |
||
280 | } |
||
281 | |||
282 | return $data; |
||
283 | } |
||
284 | } |