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 |
||
18 | class ScrapeRevisitSourceExecutor extends AbstractExecutor implements ObjectPayloadInterface |
||
19 | { |
||
20 | const NAME = 'scrape.source.revisit'; |
||
21 | |||
22 | /** |
||
23 | * @var SourceManagerInterface |
||
24 | */ |
||
25 | protected $sourceManager; |
||
26 | |||
27 | /** |
||
28 | * @var SourceRevisitor |
||
29 | */ |
||
30 | protected $revisitor; |
||
31 | |||
32 | /** |
||
33 | * @var LoggerInterface |
||
34 | */ |
||
35 | protected $logger; |
||
36 | |||
37 | /** |
||
38 | * @param SourceManagerInterface $sourceManager |
||
39 | * @param SourceRevisitor $revisitor |
||
40 | * @param LoggerInterface $logger |
||
41 | */ |
||
42 | public function __construct(SourceManagerInterface $sourceManager, SourceRevisitor $revisitor, LoggerInterface $logger) |
||
48 | |||
49 | /** |
||
50 | * @inheritdoc |
||
51 | */ |
||
52 | public function getName() |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | public function supportsObject($object) |
||
64 | |||
65 | /** |
||
66 | * @inheritdoc |
||
67 | * |
||
68 | * @param SourceInterface $object |
||
69 | */ |
||
70 | public function getObjectPayload($object) |
||
74 | |||
75 | /** |
||
76 | * @inheritdoc |
||
77 | */ |
||
78 | View Code Duplication | public function configurePayload(OptionsResolver $resolver) |
|
90 | |||
91 | /** |
||
92 | * @inheritdoc |
||
93 | */ |
||
94 | public function execute(array $payload) |
||
117 | |||
118 | /** |
||
119 | * @param int $sourceId |
||
120 | * |
||
121 | * @return SourceInterface |
||
122 | */ |
||
123 | protected function findSource($sourceId) |
||
127 | } |
||
128 |
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.