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 |
||
32 | class ItemFactory { |
||
33 | /** @var IL10N */ |
||
34 | private $l10n; |
||
35 | |||
36 | /** @var AppConfig */ |
||
37 | private $config; |
||
38 | |||
39 | /** @var ActivityManager */ |
||
40 | private $activityManager; |
||
41 | |||
42 | /** @var ItemMapper */ |
||
43 | private $itemMapper; |
||
44 | |||
45 | /** @var ILogger */ |
||
46 | private $logger; |
||
47 | |||
48 | /** |
||
49 | * ItemFactory constructor. |
||
50 | * |
||
51 | * @param IL10N $l10n |
||
52 | * @param AppConfig $appConfig |
||
53 | * @param ActivityManager $activityManager |
||
54 | * @param ItemMapper $itemMapper |
||
55 | * @param ILogger $logger |
||
56 | */ |
||
57 | View Code Duplication | public function __construct(IL10N $l10n, |
|
68 | |||
69 | /** |
||
70 | * @param File $file |
||
71 | * @return Item |
||
72 | */ |
||
73 | public function newItem(File $file) { |
||
83 | } |
||
84 |
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.