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 |
||
| 7 | class PropertyWriter extends WriterAbstract |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @param IReflectionProperty $property |
||
| 11 | * |
||
| 12 | * @return string |
||
| 13 | */ |
||
| 14 | 8 | public function writeElement(IReflectionProperty $property) |
|
| 19 | |||
| 20 | /** |
||
| 21 | * @param IReflectionProperty[] $properties |
||
| 22 | * |
||
| 23 | * @return string |
||
| 24 | */ |
||
| 25 | 10 | public function writeElements(array $properties) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * @param IReflectionProperty $property |
||
| 42 | * |
||
| 43 | * @return string |
||
| 44 | */ |
||
| 45 | 8 | public function writeVisibility(IReflectionProperty $property) |
|
| 49 | |||
| 50 | /** |
||
| 51 | * @param IReflectionProperty $property |
||
| 52 | * |
||
| 53 | * @return string |
||
| 54 | */ |
||
| 55 | 8 | View Code Duplication | public function writeType(IReflectionProperty $property) |
| 68 | |||
| 69 | /** |
||
| 70 | * @param IReflectionProperty $property |
||
| 71 | * |
||
| 72 | * @return string |
||
| 73 | */ |
||
| 74 | 8 | public function writeValue(IReflectionProperty $property) |
|
| 84 | } |
||
| 85 |
If you suppress an error, we recommend checking for the error condition explicitly: