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 |
||
21 | final class JsynExtractor |
||
22 | { |
||
23 | /** |
||
24 | * @var string |
||
25 | * |
||
26 | * Content of the JSYN File |
||
27 | */ |
||
28 | private $jsyn; |
||
29 | |||
30 | /** |
||
31 | * @var string |
||
32 | * |
||
33 | * SQL Syntax to use for script generation |
||
34 | */ |
||
35 | private $sqlSyntax; |
||
36 | |||
37 | /** |
||
38 | * @param $jsynFile string | PathUtil |
||
39 | * @param $sqlSyntax string |
||
40 | */ |
||
41 | public function __construct($jsynFile, $sqlSyntax) |
||
46 | |||
47 | /** |
||
48 | * @param $jsynFile string | PathUtil |
||
49 | * |
||
50 | * Setter function for the jsonFile global property |
||
51 | * |
||
52 | * @return void |
||
53 | */ |
||
54 | public function setJsynFile($jsynFile) |
||
68 | |||
69 | /** |
||
70 | * @param $sqlSyntax string |
||
71 | * |
||
72 | * Setter function for the sqlSyntax global property |
||
73 | * |
||
74 | * @return void |
||
75 | */ |
||
76 | public function setSqlSyntax($sqlSyntax) |
||
89 | |||
90 | /** |
||
91 | * @return array |
||
92 | */ |
||
93 | public function getJsyn() |
||
97 | |||
98 | /** |
||
99 | * Performs extraction of the appropriate sql syntax |
||
100 | * fromthe supplied jsyn file. |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | public function formatJsyn() |
||
116 | |||
117 | /** |
||
118 | * Returns the extracted jsyn as a string. |
||
119 | * |
||
120 | * @return string |
||
121 | */ |
||
122 | public function __toString() |
||
126 | } |
||
127 |
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.