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 |
||
14 | class Update extends AbstractQuery |
||
15 | { |
||
16 | use JoinTrait; |
||
17 | |||
18 | /** |
||
19 | * @const ERR_GENERATE_VALUES_NO_DATAS Exception code if no data to update. |
||
20 | */ |
||
21 | const ERR_GENERATE_VALUES_NO_DATAS = 2406001; |
||
22 | |||
23 | /** |
||
24 | * @var \BfwSql\Helpers\Quoting $quoting The quoting system |
||
25 | */ |
||
26 | protected $quoting; |
||
27 | |||
28 | /** |
||
29 | * Constructor |
||
30 | * |
||
31 | * @param \BfwSql\SqlConnect $sqlConnect Instance of SGBD connexion |
||
32 | * @param string $quoteStatus (default: QUOTE_ALL) Status to automatic |
||
33 | * quoted string value system. |
||
34 | */ |
||
35 | public function __construct( |
||
46 | |||
47 | /** |
||
48 | * Getter accessor to property quoting |
||
49 | * |
||
50 | * @return \BfwSql\Helpers\Quoting |
||
51 | */ |
||
52 | public function getQuoting(): \BfwSql\Helpers\Quoting |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | protected function defineQueriesParts() |
||
77 | |||
78 | /** |
||
79 | * {@inheritdoc} |
||
80 | */ |
||
81 | protected function obtainGenerateOrder(): array |
||
95 | |||
96 | /** |
||
97 | * Callback used by assembleRequestPart method |
||
98 | * Generate the sql query part who contains columns list and their values |
||
99 | * |
||
100 | * @return string |
||
101 | * |
||
102 | * @throws \Exception |
||
103 | */ |
||
104 | protected function generateValues(): string |
||
134 | } |
||
135 |
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.