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 |
||
| 6 | View Code Duplication | class xKerman_Restricted_EscapedStringHandler implements xKerman_Restricted_HandlerInterface |
|
| 7 | { |
||
| 8 | /** @var integer */ |
||
| 9 | const CLOSE_STRING_LENGTH = 2; |
||
| 10 | /** |
||
| 11 | * parse given `$source` as escaped string |
||
| 12 | * |
||
| 13 | * @param Source $source parser input |
||
| 14 | * @param string $args string length |
||
| 15 | * @return array |
||
| 16 | * @throws UnserializeFailedException |
||
| 17 | */ |
||
| 18 | public function handle(xKerman_Restricted_Source $source, $args) |
||
| 34 | } |
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.