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 |
||
8 | abstract class DoctrineQbIndexer implements IndexerInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var EntityManager |
||
12 | */ |
||
13 | protected $em; |
||
14 | |||
15 | public function __construct(EntityManager $em) |
||
22 | |||
23 | public function getRangeCriterias() |
||
37 | |||
38 | View Code Duplication | public function getItemsByIds(array $ids) |
|
52 | |||
53 | View Code Duplication | public function getItemsByInterval($idFrom, $idTo) |
|
68 | |||
69 | public function processItems(array $items) |
||
73 | |||
74 | public function serializeItem($item) |
||
78 | |||
79 | /** |
||
80 | * @return \Doctrine\ORM\QueryBuilder |
||
81 | */ |
||
82 | protected function getQueryBuilder() |
||
86 | |||
87 | protected function getEntityName() |
||
91 | |||
92 | protected function getRootIdentifier() |
||
96 | |||
97 | protected function getHydrationMode() |
||
101 | |||
102 | private function checkConnection() |
||
110 | } |
||
111 |
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.