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 DocContentWriter extends \Flagbit\Plantuml\TokenReflection\WriterAbstract |
||
9 | { |
||
10 | /** |
||
11 | * @param \TokenReflection\IReflectionClass $class |
||
12 | * @return string |
||
13 | */ |
||
14 | 10 | View Code Duplication | public function writeProperties(\TokenReflection\IReflectionClass $class) |
25 | |||
26 | /** |
||
27 | * @param \TokenReflection\IReflectionMethod $method |
||
28 | * @return string |
||
29 | */ |
||
30 | 1 | protected function writeProperty($name, $type) { |
|
34 | |||
35 | |||
36 | /** |
||
37 | * @param string $type |
||
38 | * @return string |
||
39 | */ |
||
40 | 1 | public function writeType($type) |
|
44 | |||
45 | /** |
||
46 | * Public by definition if in a docblock. |
||
47 | * @return string |
||
48 | */ |
||
49 | 1 | protected function writeVisibility() { |
|
52 | |||
53 | /** |
||
54 | * @param \TokenReflection\IReflectionClass $class |
||
55 | * @return string |
||
56 | */ |
||
57 | 10 | View Code Duplication | public function writeMethods(IReflectionClass $class) |
68 | |||
69 | /** |
||
70 | * @param \TokenReflection\IReflectionClass $class |
||
71 | * @return string |
||
72 | */ |
||
73 | 1 | protected function writeMethod($name, $params, $returnType) |
|
79 | |||
80 | /** |
||
81 | * @param string $returnType |
||
82 | * @return string |
||
83 | */ |
||
84 | 1 | protected function writeReturnType($returnType) { |
|
87 | |||
88 | |||
89 | /** |
||
90 | * @param string $params |
||
91 | * @return string |
||
92 | */ |
||
93 | 1 | private function writeParameters($params) |
|
97 | |||
98 | } |
||
99 |
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.