Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
53 | class ModelFieldFactory |
||
54 | { |
||
55 | |||
56 | /** |
||
57 | * @var LoaderInterface $loader |
||
58 | */ |
||
59 | private $loader; |
||
60 | |||
61 | |||
62 | |||
63 | /** |
||
64 | * ModelFieldFactory constructor. |
||
65 | * |
||
66 | * @param LoaderInterface $loader |
||
67 | */ |
||
68 | public function __construct(LoaderInterface $loader) |
||
72 | |||
73 | |||
74 | |||
75 | /** |
||
76 | * @param string $table_column |
||
77 | * @param string $nice_name |
||
78 | * @param bool $nullable |
||
79 | * @param null $default_value |
||
80 | * @return EE_All_Caps_Text_Field |
||
81 | */ |
||
82 | View Code Duplication | public function createAllCapsTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
89 | |||
90 | |||
91 | |||
92 | /** |
||
93 | * @param string $table_column |
||
94 | * @param string $nice_name |
||
95 | * @param bool $nullable |
||
96 | * @param null $default_value |
||
97 | * @param string $model_name |
||
98 | * @return EE_Any_Foreign_Model_Name_Field |
||
99 | */ |
||
100 | View Code Duplication | public function createAnyForeignModelNameField( |
|
112 | |||
113 | |||
114 | |||
115 | /** |
||
116 | * @param string $table_column |
||
117 | * @param string $nice_name |
||
118 | * @param bool $nullable |
||
119 | * @param null $default_value |
||
120 | * @return EE_Boolean_Field |
||
121 | */ |
||
122 | View Code Duplication | public function createBooleanField($table_column, $nice_name, $nullable, $default_value = null) |
|
129 | |||
130 | |||
131 | |||
132 | /** |
||
133 | * @param string $table_column |
||
134 | * @param string $nice_name |
||
135 | * @param string $timezone_string |
||
136 | * @param bool $nullable |
||
137 | * @param string $default_value |
||
138 | * @param string $date_format |
||
139 | * @param string $time_format |
||
140 | * @param string $pretty_date_format |
||
141 | * @param string $pretty_time_format |
||
142 | * @throws EE_Error |
||
143 | * @throws InvalidArgumentException |
||
144 | * @return EE_Datetime_Field |
||
145 | */ |
||
146 | public function createDatetimeField( |
||
172 | |||
173 | |||
174 | |||
175 | /** |
||
176 | * @param string $table_column |
||
177 | * @param string $nice_name |
||
178 | * @param bool $nullable |
||
179 | * @param null $default_value |
||
180 | * @return EE_DB_Only_Float_Field |
||
181 | */ |
||
182 | View Code Duplication | public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
189 | |||
190 | |||
191 | |||
192 | /** |
||
193 | * @param string $table_column |
||
194 | * @param string $nice_name |
||
195 | * @param bool $nullable |
||
196 | * @param null $default_value |
||
197 | * @return EE_DB_Only_Int_Field |
||
198 | */ |
||
199 | View Code Duplication | public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
206 | |||
207 | |||
208 | |||
209 | /** |
||
210 | * @param string $table_column |
||
211 | * @param string $nice_name |
||
212 | * @param bool $nullable |
||
213 | * @param null $default_value |
||
214 | * @return EE_DB_Only_Text_Field |
||
215 | */ |
||
216 | View Code Duplication | public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
223 | |||
224 | |||
225 | |||
226 | /** |
||
227 | * @param string $table_column |
||
228 | * @param string $nice_name |
||
229 | * @param bool $nullable |
||
230 | * @param string $default_value |
||
231 | * @return EE_Email_Field |
||
232 | */ |
||
233 | View Code Duplication | public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
240 | |||
241 | |||
242 | |||
243 | /** |
||
244 | * @param string $table_column |
||
245 | * @param string $nice_name |
||
246 | * @param bool $nullable |
||
247 | * @param null $default_value |
||
248 | * @param array $allowed_enum_values keys are values to be used in the DB, |
||
249 | * values are how they should be displayed |
||
250 | * @return EE_Enum_Integer_Field |
||
251 | */ |
||
252 | View Code Duplication | public function createEnumIntegerField( |
|
264 | |||
265 | |||
266 | |||
267 | /** |
||
268 | * @param string $table_column |
||
269 | * @param string $nice_name |
||
270 | * @param bool $nullable |
||
271 | * @param null $default_value |
||
272 | * @param array $allowed_enum_values keys are values to be used in the DB, |
||
273 | * values are how they should be displayed |
||
274 | * @return EE_Enum_Text_Field |
||
275 | */ |
||
276 | public function createEnumTextField( |
||
288 | |||
289 | |||
290 | |||
291 | /** |
||
292 | * @param string $table_column |
||
293 | * @param string $nice_name |
||
294 | * @param bool $nullable |
||
295 | * @param null $default_value |
||
296 | * @return EE_Float_Field |
||
297 | */ |
||
298 | View Code Duplication | public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
305 | |||
306 | |||
307 | |||
308 | /** |
||
309 | * @param string $table_column |
||
310 | * @param string $nice_name |
||
311 | * @param bool $nullable |
||
312 | * @param null $default_value |
||
313 | * @param string $model_name |
||
314 | * @return EE_Foreign_Key_Int_Field |
||
315 | */ |
||
316 | public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
||
323 | |||
324 | |||
325 | |||
326 | /** |
||
327 | * @param string $table_column |
||
328 | * @param string $nice_name |
||
329 | * @param bool $nullable |
||
330 | * @param null $default_value |
||
331 | * @param string $model_name |
||
332 | * @return EE_Foreign_Key_String_Field |
||
333 | */ |
||
334 | public function createForeignKeyStringField( |
||
346 | |||
347 | |||
348 | |||
349 | /** |
||
350 | * @param string $table_column |
||
351 | * @param string $nice_name |
||
352 | * @param bool $nullable |
||
353 | * @param null $default_value |
||
354 | * @return EE_Full_HTML_Field |
||
355 | */ |
||
356 | View Code Duplication | public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
363 | |||
364 | |||
365 | |||
366 | /** |
||
367 | * @param string $table_column |
||
368 | * @param string $nice_name |
||
369 | * @param bool $nullable |
||
370 | * @param null $default_value |
||
371 | * @return EE_Infinite_Integer_Field |
||
372 | */ |
||
373 | View Code Duplication | public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
380 | |||
381 | |||
382 | |||
383 | /** |
||
384 | * @param string $table_column |
||
385 | * @param string $nice_name |
||
386 | * @param bool $nullable |
||
387 | * @param null $default_value |
||
388 | * @return EE_Integer_Field |
||
389 | */ |
||
390 | View Code Duplication | public function createIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
397 | |||
398 | |||
399 | |||
400 | /** |
||
401 | * @param string $table_column |
||
402 | * @param string $nice_name |
||
403 | * @param bool $nullable |
||
404 | * @param null $default_value |
||
405 | * @return EE_Maybe_Serialized_Simple_HTML_Field |
||
406 | */ |
||
407 | View Code Duplication | public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
414 | |||
415 | |||
416 | |||
417 | /** |
||
418 | * @param string $table_column |
||
419 | * @param string $nice_name |
||
420 | * @param bool $nullable |
||
421 | * @param null $default_value |
||
422 | * @return EE_Maybe_Serialized_Text_Field |
||
423 | */ |
||
424 | View Code Duplication | public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
431 | |||
432 | |||
433 | |||
434 | /** |
||
435 | * @param string $table_column |
||
436 | * @param string $nice_name |
||
437 | * @param bool $nullable |
||
438 | * @param null $default_value |
||
439 | * @return EE_Money_Field |
||
440 | */ |
||
441 | View Code Duplication | public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
448 | |||
449 | |||
450 | |||
451 | /** |
||
452 | * @param string $table_column |
||
453 | * @param string $nice_name |
||
454 | * @param bool $nullable |
||
455 | * @param string $default_value |
||
456 | * @return EE_Plain_Text_Field |
||
457 | */ |
||
458 | View Code Duplication | public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
465 | |||
466 | |||
467 | |||
468 | /** |
||
469 | * @param string $table_column |
||
470 | * @param string $nice_name |
||
471 | * @param bool $nullable |
||
472 | * @param null $default_value |
||
473 | * @return EE_Post_Content_Field |
||
474 | */ |
||
475 | View Code Duplication | public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
482 | |||
483 | |||
484 | |||
485 | /** |
||
486 | * @param string $table_column |
||
487 | * @param string $nice_name |
||
488 | * @return EE_Primary_Key_Int_Field |
||
489 | */ |
||
490 | public function createPrimaryKeyIntField($table_column, $nice_name) |
||
494 | |||
495 | |||
496 | |||
497 | /** |
||
498 | * @param string $table_column |
||
499 | * @param string $nice_name |
||
500 | * @return EE_Primary_Key_String_Field |
||
501 | */ |
||
502 | public function createPrimaryKeyStringField($table_column, $nice_name) |
||
506 | |||
507 | |||
508 | |||
509 | /** |
||
510 | * @param string $table_column |
||
511 | * @param string $nice_name |
||
512 | * @param bool $nullable |
||
513 | * @param null $default_value |
||
514 | * @return EE_Serialized_Text_Field |
||
515 | */ |
||
516 | View Code Duplication | public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
523 | |||
524 | |||
525 | |||
526 | /** |
||
527 | * @param string $table_column |
||
528 | * @param string $nice_name |
||
529 | * @param bool $nullable |
||
530 | * @param null $default_value |
||
531 | * @return EE_Simple_HTML_Field |
||
532 | */ |
||
533 | View Code Duplication | public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
540 | |||
541 | |||
542 | |||
543 | /** |
||
544 | * @param string $table_column |
||
545 | * @param string $nice_name |
||
546 | * @param bool $nullable |
||
547 | * @param null $default_value |
||
548 | * @return EE_Slug_Field |
||
549 | */ |
||
550 | View Code Duplication | public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
557 | |||
558 | |||
559 | |||
560 | /** |
||
561 | * @param string $table_column |
||
562 | * @param string $nice_name |
||
563 | * @param bool $nullable |
||
564 | * @param null $default_value |
||
565 | * @return EE_Trashed_Flag_Field |
||
566 | */ |
||
567 | View Code Duplication | public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
574 | |||
575 | |||
576 | |||
577 | /** |
||
578 | * @param string $table_column |
||
579 | * @param string $nice_name |
||
580 | * @param bool $nullable |
||
581 | * @param mixed $default_value |
||
582 | * @param array $values If additional stati are to be used other than the default WP statuses, |
||
583 | * then they can be registered via this property. |
||
584 | * The format of the array should be as follows: |
||
585 | * array( |
||
586 | * 'status_reference' => array( |
||
587 | * 'label' => __('Status Reference Label', 'event_espresso'), |
||
588 | * 'public' => true, // whether this status should be shown on the frontend of the site |
||
589 | * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
||
590 | * 'show_in_admin_all_list' => true, // whether this status is included in queries |
||
591 | * for the admin "all" view in list table views. |
||
592 | * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
||
593 | * of the admin list tables (i.e. Status Reference(2) ) |
||
594 | * 'label_count' => _n_noop( |
||
595 | * 'Status Reference <span class="count">(%s)</span>', |
||
596 | * 'Status References <span class="count">(%s)</span>' |
||
597 | * ), // the text to display on the admin screen |
||
598 | * ( or you won't see your status count ). |
||
599 | * ) |
||
600 | * ) |
||
601 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
||
602 | * @return EE_WP_Post_Status_Field |
||
603 | */ |
||
604 | View Code Duplication | public function createWpPostStatusField( |
|
616 | |||
617 | |||
618 | |||
619 | /** |
||
620 | * @param string $post_type |
||
621 | * @return EE_WP_Post_Type_Field |
||
622 | */ |
||
623 | public function createWpPostTypeField($post_type) |
||
627 | |||
628 | |||
629 | |||
630 | /** |
||
631 | * @param string $table_column |
||
632 | * @param string $nice_name |
||
633 | * @param bool $nullable |
||
634 | * @return EE_WP_User_Field |
||
635 | */ |
||
636 | public function createWpUserField($table_column, $nice_name, $nullable) |
||
640 | |||
641 | |||
642 | |||
643 | } |
||
644 | // Location: core/services/database/ModelFieldFactory.php |
||
645 |