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 |
||
27 | class ShardCommand extends AbstractCommand |
||
28 | { |
||
29 | protected function configure() |
||
37 | |||
38 | /** |
||
39 | * @param InputInterface $input |
||
40 | * @param OutputInterface $output |
||
41 | * @return int|null|void |
||
42 | */ |
||
43 | protected function execute(InputInterface $input, OutputInterface $output) |
||
65 | |||
66 | /** |
||
67 | * @param SchemaManager $sm |
||
68 | * @param object $document |
||
69 | */ |
||
70 | protected function processDocumentIndex(SchemaManager $sm, $document) |
||
74 | |||
75 | /** |
||
76 | * @param SchemaManager $sm |
||
77 | */ |
||
78 | protected function processIndex(SchemaManager $sm) |
||
82 | |||
83 | /** |
||
84 | * @param SchemaManager $sm |
||
85 | * @param object $document |
||
86 | * @throws \BadMethodCallException |
||
87 | */ |
||
88 | protected function processDocumentCollection(SchemaManager $sm, $document) |
||
92 | |||
93 | /** |
||
94 | * @param SchemaManager $sm |
||
95 | * @throws \BadMethodCallException |
||
96 | */ |
||
97 | protected function processCollection(SchemaManager $sm) |
||
101 | |||
102 | /** |
||
103 | * @param SchemaManager $sm |
||
104 | * @param object $document |
||
105 | * @throws \BadMethodCallException |
||
106 | */ |
||
107 | protected function processDocumentDb(SchemaManager $sm, $document) |
||
111 | |||
112 | /** |
||
113 | * @param SchemaManager $sm |
||
114 | * @throws \BadMethodCallException |
||
115 | */ |
||
116 | protected function processDb(SchemaManager $sm) |
||
120 | } |
||
121 |
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.