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 ColumnList extends AbstractList |
||
8 | { |
||
9 | /** |
||
10 | * @var \BfwSql\Queries\Parts\Table $table The table where are columns |
||
11 | */ |
||
12 | protected $table; |
||
13 | |||
14 | /** |
||
15 | * {@inheritdoc} |
||
16 | */ |
||
17 | protected $separator = ','; |
||
18 | |||
19 | /** |
||
20 | * {@inheritdoc} |
||
21 | * |
||
22 | * @param \BfwSql\Queries\AbstractQuery $querySystem |
||
23 | * @param \BfwSql\Queries\Parts\Table $table The table where are column |
||
24 | */ |
||
25 | public function __construct(AbstractQuery $querySystem, Table $table) |
||
30 | |||
31 | /** |
||
32 | * Getter accessor to property table |
||
33 | * |
||
34 | * @return \BfwSql\Queries\Parts\Table |
||
35 | */ |
||
36 | public function getTable(): Table |
||
40 | |||
41 | /** |
||
42 | * Magic method __invoke, used when the user call object like a function |
||
43 | * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke |
||
44 | * |
||
45 | * @param array $columns The list of columns to declare |
||
46 | * The key into the array is the shortcut of the column. |
||
47 | * The value is the column name. |
||
48 | * If no key is defined (so integer), the column will not have shortcut. |
||
49 | * |
||
50 | * @return void |
||
51 | */ |
||
52 | public function __invoke(array $columns) |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | View Code Duplication | public function generate(): string |
|
82 | } |
||
83 |
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.