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 MethodWriter extends \Flagbit\Plantuml\TokenReflection\WriterAbstract |
||
9 | { |
||
10 | /** |
||
11 | * @param \TokenReflection\IReflectionMethod $method |
||
12 | * @return string |
||
13 | */ |
||
14 | 27 | public function writeElement(IReflectionMethod $method) |
|
20 | |||
21 | /** |
||
22 | * @param IReflectionMethod[] $methods |
||
23 | * @return string |
||
24 | */ |
||
25 | 16 | public function writeElements(array $methods) |
|
38 | |||
39 | /** |
||
40 | * @param \TokenReflection\IReflectionMethod $method |
||
41 | * @return string |
||
42 | */ |
||
43 | 27 | private function writeVisibility(IReflectionMethod $method) |
|
47 | |||
48 | /** |
||
49 | * @param \TokenReflection\IReflectionMethod $method |
||
50 | * @return string |
||
51 | */ |
||
52 | 27 | private function writeParameters(IReflectionMethod $method) |
|
65 | |||
66 | /** |
||
67 | * @param IReflectionMethod $method |
||
68 | * @param IReflectionParameter $parameter |
||
69 | * @return string |
||
70 | */ |
||
71 | 11 | private function writeParameter(IReflectionMethod $method, IReflectionParameter $parameter) |
|
91 | |||
92 | /** |
||
93 | * @param \TokenReflection\IReflectionMethod $method |
||
94 | * @return string |
||
95 | */ |
||
96 | 27 | View Code Duplication | private function writeReturnType(IReflectionMethod $method) |
109 | |||
110 | /** |
||
111 | * Overide format line if needed |
||
112 | * @param string $string |
||
113 | * @return string |
||
114 | */ |
||
115 | 27 | public function formatLine($string) |
|
122 | |||
123 | } |
||
124 |
If you suppress an error, we recommend checking for the error condition explicitly: