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 |
||
8 | class CodeFileGenerator extends CodeGenerator { |
||
9 | |||
10 | /** |
||
11 | * @param CodeFileGeneratorConfig|array $config |
||
12 | */ |
||
13 | 4 | View Code Duplication | public function __construct($config = null) { |
14 | 4 | if (is_array($config)) { |
|
15 | 3 | $this->config = new CodeFileGeneratorConfig($config); |
|
16 | 4 | } else if ($config instanceof CodeFileGeneratorConfig) { |
|
17 | $this->config = $config; |
||
18 | } else { |
||
19 | 1 | $this->config = new CodeFileGeneratorConfig(); |
|
20 | } |
||
21 | |||
22 | 4 | $this->init(); |
|
23 | 4 | } |
|
24 | |||
25 | /** |
||
26 | * @return CodeFileGeneratorConfig |
||
27 | */ |
||
28 | public function getConfig() { |
||
31 | |||
32 | 4 | public function generate(GenerateableInterface $model) { |
|
58 | } |
||
59 |