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 ScrapeRevisitUrlsCommand extends Command |
||
18 | { |
||
19 | /** |
||
20 | * @var ManagerRegistry |
||
21 | */ |
||
22 | protected $doctrine; |
||
23 | |||
24 | /** |
||
25 | * @var SourceManagerInterface |
||
26 | */ |
||
27 | protected $sourceManager; |
||
28 | |||
29 | /** |
||
30 | * @var SourceRevisitor |
||
31 | */ |
||
32 | protected $revisitor; |
||
33 | |||
34 | /** |
||
35 | * @param ManagerRegistry $doctrine |
||
36 | * @param SourceManagerInterface $sourceManager |
||
37 | * @param SourceRevisitor $revisitor |
||
38 | */ |
||
39 | View Code Duplication | public function __construct(ManagerRegistry $doctrine, SourceManagerInterface $sourceManager, SourceRevisitor $revisitor) |
|
47 | |||
48 | /** |
||
49 | * @inheritdoc |
||
50 | */ |
||
51 | View Code Duplication | protected function configure() |
|
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | */ |
||
68 | protected function execute(InputInterface $input, OutputInterface $output) |
||
90 | |||
91 | /** |
||
92 | * @param integer[] $ids |
||
93 | * |
||
94 | * @return ScraperEntity[] |
||
95 | */ |
||
96 | View Code Duplication | protected function findScrapers(array $ids) |
|
106 | } |
||
107 |
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.