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 |
||
16 | class ListShortcodesAction extends AbstractRestAction |
||
17 | { |
||
18 | use PaginatorUtilsTrait; |
||
19 | |||
20 | /** |
||
21 | * @var ShortUrlServiceInterface |
||
22 | */ |
||
23 | private $shortUrlService; |
||
24 | /** |
||
25 | * @var TranslatorInterface |
||
26 | */ |
||
27 | private $translator; |
||
28 | |||
29 | /** |
||
30 | * ListShortcodesAction constructor. |
||
31 | * @param ShortUrlServiceInterface|ShortUrlService $shortUrlService |
||
32 | * @param TranslatorInterface $translator |
||
33 | * @param LoggerInterface $logger |
||
34 | * |
||
35 | * @Inject({ShortUrlService::class, "translator", "Logger_Shlink"}) |
||
36 | */ |
||
37 | 2 | View Code Duplication | public function __construct( |
46 | |||
47 | /** |
||
48 | * @param Request $request |
||
49 | * @param Response $response |
||
50 | * @param callable|null $out |
||
51 | * @return null|Response |
||
52 | */ |
||
53 | 2 | public function dispatch(Request $request, Response $response, callable $out = null) |
|
67 | |||
68 | /** |
||
69 | * @param array $query |
||
70 | * @return string |
||
71 | */ |
||
72 | public function queryToListParams(array $query) |
||
81 | } |
||
82 |
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.