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 |
||
26 | abstract class IncrementalIndexer extends Indexer |
||
27 | { |
||
28 | /** |
||
29 | * @deprecated Kept for compatibility with consumers of Indexer, performs purge first & recreate of index second. |
||
30 | */ |
||
31 | final public function createSearchIndex(OutputInterface $output, $iterationCount, $commit) |
||
65 | |||
66 | /** |
||
67 | * Updates search engine index based on Content id's. |
||
68 | * |
||
69 | * If content is: |
||
70 | * - deleted (NotFoundException) |
||
71 | * - not published (draft or trashed) |
||
72 | * Then item is removed from index, if not it is added/updated. |
||
73 | * |
||
74 | * @param int[] $contentIds |
||
75 | * @param bool $commit |
||
76 | */ |
||
77 | abstract public function updateSearchIndex(array $contentIds, $commit); |
||
78 | |||
79 | /** |
||
80 | * Purges whole index, should only be done if user asked for it. |
||
81 | */ |
||
82 | abstract public function purge(); |
||
83 | |||
84 | /** |
||
85 | * Return human readable name of given search engine (and if custom indexer you can append that to). |
||
86 | * |
||
87 | * @return string |
||
88 | */ |
||
89 | abstract public function getName(); |
||
90 | } |
||
91 |
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.