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 | * @throws EE_Error |
||
139 | * @throws InvalidArgumentException |
||
140 | * @return EE_Datetime_Field |
||
141 | */ |
||
142 | View Code Duplication | public function createDatetimeField( |
|
158 | |||
159 | |||
160 | |||
161 | /** |
||
162 | * @param string $table_column |
||
163 | * @param string $nice_name |
||
164 | * @param bool $nullable |
||
165 | * @param null $default_value |
||
166 | * @return EE_DB_Only_Float_Field |
||
167 | */ |
||
168 | View Code Duplication | public function createDbOnlyFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * @param string $table_column |
||
180 | * @param string $nice_name |
||
181 | * @param bool $nullable |
||
182 | * @param null $default_value |
||
183 | * @return EE_DB_Only_Int_Field |
||
184 | */ |
||
185 | View Code Duplication | public function createDbOnlyIntField($table_column, $nice_name, $nullable, $default_value = null) |
|
192 | |||
193 | |||
194 | |||
195 | /** |
||
196 | * @param string $table_column |
||
197 | * @param string $nice_name |
||
198 | * @param bool $nullable |
||
199 | * @param null $default_value |
||
200 | * @return EE_DB_Only_Text_Field |
||
201 | */ |
||
202 | View Code Duplication | public function createDbOnlyTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
209 | |||
210 | |||
211 | |||
212 | /** |
||
213 | * @param string $table_column |
||
214 | * @param string $nice_name |
||
215 | * @param bool $nullable |
||
216 | * @param string $default_value |
||
217 | * @return EE_Email_Field |
||
218 | */ |
||
219 | View Code Duplication | public function createEmailField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
226 | |||
227 | |||
228 | |||
229 | /** |
||
230 | * @param string $table_column |
||
231 | * @param string $nice_name |
||
232 | * @param bool $nullable |
||
233 | * @param null $default_value |
||
234 | * @param array $allowed_enum_values keys are values to be used in the DB, |
||
235 | * values are how they should be displayed |
||
236 | * @return EE_Enum_Integer_Field |
||
237 | */ |
||
238 | View Code Duplication | public function createEnumIntegerField( |
|
250 | |||
251 | |||
252 | |||
253 | /** |
||
254 | * @param string $table_column |
||
255 | * @param string $nice_name |
||
256 | * @param bool $nullable |
||
257 | * @param null $default_value |
||
258 | * @param array $allowed_enum_values keys are values to be used in the DB, |
||
259 | * values are how they should be displayed |
||
260 | * @return EE_Enum_Text_Field |
||
261 | */ |
||
262 | View Code Duplication | public function createEnumTextField( |
|
263 | $table_column, |
||
264 | $nice_name, |
||
265 | $nullable, |
||
266 | $default_value, |
||
267 | array $allowed_enum_values |
||
268 | ) { |
||
269 | return $this->loader->getNew( |
||
270 | 'EE_Enum_Text_Field', |
||
271 | array($table_column, $nice_name, $nullable, $default_value, $allowed_enum_values) |
||
272 | ); |
||
273 | } |
||
274 | |||
275 | |||
276 | |||
277 | /** |
||
278 | * @param string $table_column |
||
279 | * @param string $nice_name |
||
280 | * @param bool $nullable |
||
281 | * @param null $default_value |
||
282 | * @return EE_Float_Field |
||
283 | */ |
||
284 | View Code Duplication | public function createFloatField($table_column, $nice_name, $nullable, $default_value = null) |
|
291 | |||
292 | |||
293 | |||
294 | /** |
||
295 | * @param string $table_column |
||
296 | * @param string $nice_name |
||
297 | * @param bool $nullable |
||
298 | * @param null $default_value |
||
299 | * @param string $model_name |
||
300 | * @return EE_Foreign_Key_Int_Field |
||
301 | */ |
||
302 | View Code Duplication | public function createForeignKeyIntField($table_column, $nice_name, $nullable, $default_value, $model_name) |
|
303 | { |
||
304 | return $this->loader->getNew( |
||
305 | 'EE_Foreign_Key_Int_Field', |
||
306 | array($table_column, $nice_name, $nullable, $default_value, $model_name) |
||
307 | ); |
||
308 | } |
||
309 | |||
310 | |||
311 | |||
312 | /** |
||
313 | * @param string $table_column |
||
314 | * @param string $nice_name |
||
315 | * @param bool $nullable |
||
316 | * @param null $default_value |
||
317 | * @param string $model_name |
||
318 | * @return EE_Foreign_Key_String_Field |
||
319 | */ |
||
320 | View Code Duplication | public function createForeignKeyStringField( |
|
321 | $table_column, |
||
322 | $nice_name, |
||
323 | $nullable, |
||
324 | $default_value, |
||
325 | $model_name |
||
326 | ) { |
||
327 | return $this->loader->getNew( |
||
328 | 'EE_Foreign_Key_String_Field', |
||
329 | array($table_column, $nice_name, $nullable, $default_value, $model_name) |
||
330 | ); |
||
331 | } |
||
332 | |||
333 | |||
334 | |||
335 | /** |
||
336 | * @param string $table_column |
||
337 | * @param string $nice_name |
||
338 | * @param bool $nullable |
||
339 | * @param null $default_value |
||
340 | * @return EE_Full_HTML_Field |
||
341 | */ |
||
342 | View Code Duplication | public function createFullHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
349 | |||
350 | |||
351 | |||
352 | /** |
||
353 | * @param string $table_column |
||
354 | * @param string $nice_name |
||
355 | * @param bool $nullable |
||
356 | * @param null $default_value |
||
357 | * @return EE_Infinite_Integer_Field |
||
358 | */ |
||
359 | View Code Duplication | public function createInfiniteIntegerField($table_column, $nice_name, $nullable, $default_value = null) |
|
366 | |||
367 | |||
368 | |||
369 | /** |
||
370 | * @param string $table_column |
||
371 | * @param string $nice_name |
||
372 | * @param bool $nullable |
||
373 | * @param integer $default_value |
||
374 | * @return EE_Integer_Field |
||
375 | */ |
||
376 | View Code Duplication | public function createIntegerField($table_column, $nice_name, $nullable = false, $default_value = 0) |
|
383 | |||
384 | |||
385 | |||
386 | /** |
||
387 | * @param string $table_column |
||
388 | * @param string $nice_name |
||
389 | * @param bool $nullable |
||
390 | * @param null $default_value |
||
391 | * @return EE_Maybe_Serialized_Simple_HTML_Field |
||
392 | */ |
||
393 | View Code Duplication | public function createMaybeSerializedSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
400 | |||
401 | |||
402 | |||
403 | /** |
||
404 | * @param string $table_column |
||
405 | * @param string $nice_name |
||
406 | * @param bool $nullable |
||
407 | * @param null $default_value |
||
408 | * @return EE_Maybe_Serialized_Text_Field |
||
409 | */ |
||
410 | View Code Duplication | public function createMaybeSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
417 | |||
418 | |||
419 | |||
420 | /** |
||
421 | * @param string $table_column |
||
422 | * @param string $nice_name |
||
423 | * @param bool $nullable |
||
424 | * @param null $default_value |
||
425 | * @return EE_Money_Field |
||
426 | */ |
||
427 | View Code Duplication | public function createMoneyField($table_column, $nice_name, $nullable, $default_value = null) |
|
434 | |||
435 | |||
436 | |||
437 | /** |
||
438 | * @param string $table_column |
||
439 | * @param string $nice_name |
||
440 | * @param bool $nullable |
||
441 | * @param string $default_value |
||
442 | * @return EE_Plain_Text_Field |
||
443 | */ |
||
444 | View Code Duplication | public function createPlainTextField($table_column, $nice_name, $nullable = true, $default_value = '') |
|
451 | |||
452 | |||
453 | |||
454 | /** |
||
455 | * @param string $table_column |
||
456 | * @param string $nice_name |
||
457 | * @param bool $nullable |
||
458 | * @param null $default_value |
||
459 | * @return EE_Post_Content_Field |
||
460 | */ |
||
461 | View Code Duplication | public function createPostContentField($table_column, $nice_name, $nullable, $default_value = null) |
|
468 | |||
469 | |||
470 | |||
471 | /** |
||
472 | * @param string $table_column |
||
473 | * @param string $nice_name |
||
474 | * @return EE_Primary_Key_Int_Field |
||
475 | */ |
||
476 | public function createPrimaryKeyIntField($table_column, $nice_name) |
||
480 | |||
481 | |||
482 | |||
483 | /** |
||
484 | * @param string $table_column |
||
485 | * @param string $nice_name |
||
486 | * @return EE_Primary_Key_String_Field |
||
487 | */ |
||
488 | public function createPrimaryKeyStringField($table_column, $nice_name) |
||
492 | |||
493 | |||
494 | |||
495 | /** |
||
496 | * @param string $table_column |
||
497 | * @param string $nice_name |
||
498 | * @param bool $nullable |
||
499 | * @param null $default_value |
||
500 | * @return EE_Serialized_Text_Field |
||
501 | */ |
||
502 | View Code Duplication | public function createSerializedTextField($table_column, $nice_name, $nullable, $default_value = null) |
|
509 | |||
510 | |||
511 | |||
512 | /** |
||
513 | * @param string $table_column |
||
514 | * @param string $nice_name |
||
515 | * @param bool $nullable |
||
516 | * @param null $default_value |
||
517 | * @return EE_Simple_HTML_Field |
||
518 | */ |
||
519 | View Code Duplication | public function createSimpleHtmlField($table_column, $nice_name, $nullable, $default_value = null) |
|
526 | |||
527 | |||
528 | |||
529 | /** |
||
530 | * @param string $table_column |
||
531 | * @param string $nice_name |
||
532 | * @param bool $nullable |
||
533 | * @param null $default_value |
||
534 | * @return EE_Slug_Field |
||
535 | */ |
||
536 | View Code Duplication | public function createSlugField($table_column, $nice_name, $nullable = false, $default_value = null) |
|
543 | |||
544 | |||
545 | |||
546 | /** |
||
547 | * @param string $table_column |
||
548 | * @param string $nice_name |
||
549 | * @param bool $nullable |
||
550 | * @param null $default_value |
||
551 | * @return EE_Trashed_Flag_Field |
||
552 | */ |
||
553 | View Code Duplication | public function createTrashedFlagField($table_column, $nice_name, $nullable, $default_value = null) |
|
560 | |||
561 | |||
562 | |||
563 | /** |
||
564 | * @param string $table_column |
||
565 | * @param string $nice_name |
||
566 | * @param bool $nullable |
||
567 | * @param mixed $default_value |
||
568 | * @param array $values If additional stati are to be used other than the default WP statuses, |
||
569 | * then they can be registered via this property. |
||
570 | * The format of the array should be as follows: |
||
571 | * array( |
||
572 | * 'status_reference' => array( |
||
573 | * 'label' => __('Status Reference Label', 'event_espresso'), |
||
574 | * 'public' => true, // whether this status should be shown on the frontend of the site |
||
575 | * 'exclude_from_search' => false, // whether this status should be excluded from wp searches |
||
576 | * 'show_in_admin_all_list' => true, // whether this status is included in queries |
||
577 | * for the admin "all" view in list table views. |
||
578 | * 'show_in_admin_status_list' => true, // show in the list of statuses with post counts at the top |
||
579 | * of the admin list tables (i.e. Status Reference(2) ) |
||
580 | * 'label_count' => _n_noop( |
||
581 | * 'Status Reference <span class="count">(%s)</span>', |
||
582 | * 'Status References <span class="count">(%s)</span>' |
||
583 | * ), // the text to display on the admin screen |
||
584 | * ( or you won't see your status count ). |
||
585 | * ) |
||
586 | * ) |
||
587 | * @link http://codex.wordpress.org/Function_Reference/register_post_status for more info |
||
588 | * @return EE_WP_Post_Status_Field |
||
589 | */ |
||
590 | View Code Duplication | public function createWpPostStatusField( |
|
602 | |||
603 | |||
604 | |||
605 | /** |
||
606 | * @param string $post_type |
||
607 | * @return EE_WP_Post_Type_Field |
||
608 | */ |
||
609 | public function createWpPostTypeField($post_type) |
||
613 | |||
614 | |||
615 | |||
616 | /** |
||
617 | * @param string $table_column |
||
618 | * @param string $nice_name |
||
619 | * @param bool $nullable |
||
620 | * @return EE_WP_User_Field |
||
621 | */ |
||
622 | public function createWpUserField($table_column, $nice_name, $nullable) |
||
626 | |||
627 | |||
628 | |||
629 | } |
||
630 | // Location: core/services/database/ModelFieldFactory.php |
||
631 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.