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 |
||
| 7 | class Table extends HasMany |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var string |
||
| 11 | */ |
||
| 12 | protected $view = 'admin::form.hasmanytable'; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * Table constructor. |
||
| 16 | * |
||
| 17 | * @param string $column |
||
| 18 | * @param array $arguments |
||
| 19 | */ |
||
| 20 | public function __construct($column, $arguments = []) |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @return array |
||
| 36 | */ |
||
| 37 | protected function buildRelatedForms() |
||
| 61 | |||
| 62 | public function prepare($input) |
||
| 75 | |||
| 76 | protected function getKeyName() |
||
| 84 | |||
| 85 | View Code Duplication | protected function buildNestedForm($column, \Closure $builder, $key = null) |
|
| 98 | |||
| 99 | public function render() |
||
| 103 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.