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 |
||
17 | class N2WHelper |
||
18 | { |
||
19 | /** |
||
20 | * Component hổ trợ việc chuyển đổi số sang chữ số. |
||
21 | * |
||
22 | * @var array|string|callable|N2W |
||
23 | */ |
||
24 | protected static $n2w = 'n2w'; |
||
25 | |||
26 | /** |
||
27 | * Chuyển đổi số sang chữ số. |
||
28 | * |
||
29 | * @param $number |
||
30 | * @param string $dictionary |
||
31 | * @return string |
||
32 | */ |
||
33 | View Code Duplication | public static function toWords($number, string $dictionary = N2W::STANDARD_DICTIONARY): string |
|
43 | |||
44 | /** |
||
45 | * Chuyển đổi số sang tiền tệ. |
||
46 | * |
||
47 | * @param $number |
||
48 | * @param string $unit |
||
49 | * @param string $dictionary |
||
50 | * @return string |
||
51 | */ |
||
52 | View Code Duplication | public static function toCurrency($number, $unit = 'đồng', string $dictionary = N2W::STANDARD_DICTIONARY): string |
|
62 | } |
||
63 |
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.