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 |
||
9 | class PunycodeWrapper |
||
10 | { |
||
11 | /** |
||
12 | * @var Punycode |
||
13 | */ |
||
14 | private static $punycode; |
||
15 | |||
16 | /** |
||
17 | * @var bool |
||
18 | */ |
||
19 | private $idnSupport = false; |
||
20 | |||
21 | 14 | public function __construct() |
|
37 | |||
38 | /** |
||
39 | * Encode a domain to its Punycode version |
||
40 | * |
||
41 | * @param string $input Domain name in Unicode to be encoded |
||
42 | * |
||
43 | * @return string Punycode representation in ASCII |
||
44 | */ |
||
45 | 13 | View Code Duplication | public function encode($input): string |
58 | |||
59 | /** |
||
60 | * Decode a Punycode domain name to its Unicode counterpart |
||
61 | * |
||
62 | * @param string $input Domain name in Punycode |
||
63 | * |
||
64 | * @return string Unicode domain name |
||
65 | */ |
||
66 | 11 | View Code Duplication | public function decode($input): string |
78 | } |
||
79 |
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.