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 |
||
13 | class Service extends AbstractChecker |
||
14 | 3 | { |
|
15 | /** |
||
16 | 3 | * @var string |
|
17 | 3 | */ |
|
18 | 3 | protected $target = 'name'; |
|
19 | 3 | ||
20 | 3 | /** |
|
21 | * @param string $command |
||
22 | 3 | * |
|
23 | * @return string |
||
24 | 3 | */ |
|
25 | 3 | protected function runCommand($command) |
|
40 | 1 | ||
41 | /** |
||
42 | * @param string $name |
||
43 | 1 | * @param boolean $expectExists |
|
44 | * @param array $task |
||
45 | 1 | * |
|
46 | * @throws FailException |
||
47 | 1 | * @throws SuccessException |
|
48 | */ |
||
49 | View Code Duplication | protected function testExists($name, $expectExists, array $task) |
|
61 | |||
62 | /** |
||
63 | * @param string $name |
||
64 | * @param boolean $expectWhich |
||
65 | * @param array $task |
||
66 | * |
||
67 | * @throws FailException |
||
68 | * @throws SuccessException |
||
69 | */ |
||
70 | View Code Duplication | protected function testWhich($name, $expectWhich, array $task) |
|
82 | |||
83 | /** |
||
84 | * @param string $name |
||
85 | * @param string $version |
||
86 | * @param array $task |
||
87 | * |
||
88 | * @throws FailException |
||
89 | * @throws SuccessException |
||
90 | */ |
||
91 | protected function testVersion($name, $version, array $task) |
||
105 | } |
||
106 |
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.