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 |
||
5 | class Join extends Table |
||
6 | { |
||
7 | /** |
||
8 | * @var string $on The on condition used for a join |
||
9 | */ |
||
10 | protected $on = ''; |
||
11 | |||
12 | /** |
||
13 | * Getter accessor to property on |
||
14 | * |
||
15 | * @return string |
||
16 | */ |
||
17 | public function getOn(): string |
||
21 | |||
22 | /** |
||
23 | * Magic method __invoke, used when the user call object like a function |
||
24 | * @link http://php.net/manual/en/language.oop5.magic.php#object.invoke |
||
25 | * |
||
26 | * @param string|array $nameInfos The name (and shortcut) of the table |
||
27 | * @param string|array|null $columns Columns of this table to use |
||
28 | * into the request |
||
29 | * @param string $on The ON condition used by the join |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | public function __invoke($nameInfos, $columns = null, string $on = '') |
||
38 | |||
39 | /** |
||
40 | * {@inheritdoc} |
||
41 | */ |
||
42 | View Code Duplication | public function generate(): string |
|
53 | } |
||
54 |
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.