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 |
||
12 | class CategoryUrlPathChecker implements UrlPathUsedChecker |
||
13 | { |
||
14 | /** |
||
15 | * @var CategoryResolverInterface |
||
16 | */ |
||
17 | private $categoryResolver; |
||
18 | |||
19 | /** |
||
20 | * @var StoreManagerInterface |
||
21 | */ |
||
22 | private $storeManager; |
||
23 | |||
24 | /** |
||
25 | * @param CategoryResolverInterface $categoryResolver |
||
26 | * @param StoreManagerInterface $storeManager |
||
27 | */ |
||
28 | public function __construct(CategoryResolverInterface $categoryResolver, StoreManagerInterface $storeManager) |
||
33 | |||
34 | /** |
||
35 | * @param UrlPath $urlPath |
||
36 | * @param int $storeId |
||
37 | * |
||
38 | * @return EntityData[] |
||
39 | */ |
||
40 | public function check(UrlPath $urlPath, int $storeId) : array |
||
46 | |||
47 | /** |
||
48 | * @param UrlPath $urlPath |
||
49 | * @param int $storeId |
||
50 | * |
||
51 | * @return int |
||
52 | */ |
||
53 | View Code Duplication | private function resolveParentCategoryId(UrlPath $urlPath, int $storeId) : int |
|
63 | } |
||
64 |
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.