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 |
||
12 | class EntityRepository extends BaseEntityRepository implements RepositoryInterface |
||
13 | { |
||
14 | /** |
||
15 | * @return \Doctrine\ORM\Query\Expr |
||
16 | */ |
||
17 | public function expr() |
||
21 | |||
22 | /** |
||
23 | * @return \Doctrine\ORM\EntityManager |
||
24 | */ |
||
25 | public function getManager() |
||
29 | |||
30 | /** |
||
31 | * @return string |
||
32 | */ |
||
33 | public function getEntityName() |
||
37 | |||
38 | /** |
||
39 | * @deprecated Remove all resource creation logics to ResourceFactory. |
||
40 | */ |
||
41 | public function createNew() |
||
47 | |||
48 | /** |
||
49 | * @param QueryBuilder $queryBuilder |
||
50 | * @param $value |
||
51 | * @param $properties |
||
52 | */ |
||
53 | protected function applySearchCriteria(QueryBuilder $queryBuilder, $value, $properties) |
||
76 | |||
77 | /** |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | protected function applyCriteria(QueryBuilder $queryBuilder, array $criteria = array()) |
||
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | View Code Duplication | public function createUserList(array $criteria = null, array $orderBy = null) |
|
104 | |||
105 | /** |
||
106 | * {@inheritdoc} |
||
107 | */ |
||
108 | View Code Duplication | public function createUserPaginator(array $criteria = null, array $orderBy = null) |
|
116 | |||
117 | /** |
||
118 | * @param QueryBuilder $queryBuilder |
||
119 | * @param array $sorting |
||
120 | */ |
||
121 | protected function applySorting(QueryBuilder $queryBuilder, array $sorting = null) |
||
133 | |||
134 | /** |
||
135 | * @param QueryBuilder $queryBuilder |
||
136 | * @param $propertyPath |
||
137 | * @param $usingHidden |
||
138 | * |
||
139 | * @return bool|string |
||
140 | */ |
||
141 | private function addAssociation(QueryBuilder $queryBuilder, $propertyPath, $usingHidden = true) |
||
175 | |||
176 | /** |
||
177 | * @param QueryBuilder $queryBuilder |
||
178 | * @param string $name |
||
179 | * @param string $order |
||
180 | * |
||
181 | * @return bool|string |
||
182 | */ |
||
183 | private function addAssociateOrder(QueryBuilder $queryBuilder, $name, $order) |
||
192 | |||
193 | public function bulkUpdate(array $paths, array $criteria = array()) |
||
217 | } |
||
218 |
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.