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 |
||
30 | trait FromTrait |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | public function from($table, /*# string */ $alias = '') |
||
49 | |||
50 | /** |
||
51 | * {@inheritDoc} |
||
52 | */ |
||
53 | public function table($table, /*# string */ $alias = '') |
||
59 | |||
60 | /** |
||
61 | * from multiple tables |
||
62 | * |
||
63 | * @param array $tables |
||
64 | * @access protected |
||
65 | */ |
||
66 | protected function multipleFrom(array $tables) |
||
76 | |||
77 | /** |
||
78 | * Build FROM |
||
79 | * |
||
80 | * @return array |
||
81 | * @access protected |
||
82 | */ |
||
83 | protected function buildFrom(array $settings)/*# : string */ |
||
94 | |||
95 | abstract protected function quoteAlias($alias)/*# : string */; |
||
104 | } |
||
105 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.