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 |
||
51 | class CirclesQueryHelper { |
||
52 | |||
53 | |||
54 | /** @var CoreRequestBuilder */ |
||
55 | private $coreRequestBuilder; |
||
56 | |||
57 | /** @var CoreQueryBuilder */ |
||
58 | private $queryBuilder; |
||
59 | |||
60 | /** @var FederatedUserService */ |
||
61 | private $federatedUserService; |
||
62 | |||
63 | |||
64 | /** |
||
65 | * CirclesQueryHelper constructor. |
||
66 | * |
||
67 | * @param CoreRequestBuilder $coreRequestBuilder |
||
68 | * @param FederatedUserService $federatedUserService |
||
69 | */ |
||
70 | public function __construct( |
||
77 | |||
78 | |||
79 | /** |
||
80 | * @return IQueryBuilder |
||
81 | */ |
||
82 | public function getQueryBuilder(): IQueryBuilder { |
||
87 | |||
88 | |||
89 | /** |
||
90 | * @param string $alias |
||
91 | * @param string $field |
||
92 | * @param bool $fullDetails |
||
93 | * |
||
94 | * @return ICompositeExpression |
||
95 | * @throws RequestBuilderException |
||
96 | * @throws FederatedUserNotFoundException |
||
97 | */ |
||
98 | public function limitToSession( |
||
124 | |||
125 | |||
126 | /** |
||
127 | * @param string $alias |
||
128 | * @param string $field |
||
129 | * @param IFederatedUser $federatedUser |
||
130 | * @param bool $fullDetails |
||
131 | * |
||
132 | * @return ICompositeExpression |
||
133 | * @throws RequestBuilderException |
||
134 | */ |
||
135 | View Code Duplication | public function limitToInheritedMembers( |
|
157 | |||
158 | |||
159 | /** |
||
160 | * @param string $field |
||
161 | * @param string $alias |
||
162 | * |
||
163 | * @throws RequestBuilderException |
||
164 | */ |
||
165 | View Code Duplication | public function addCircleDetails( |
|
179 | |||
180 | |||
181 | /** |
||
182 | * @param array $data |
||
183 | * |
||
184 | * @return Circle |
||
185 | * @throws CircleNotFoundException |
||
186 | */ |
||
187 | public function extractCircle(array $data): Circle { |
||
196 | |||
197 | } |
||
198 | |||
199 |
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.