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 |
||
9 | abstract class SingleRequestApi implements CrudsApiInterface |
||
10 | { |
||
11 | /** {@inheritdoc} */ |
||
12 | View Code Duplication | public function count(array $criteria = []) |
|
23 | |||
24 | /** {@inheritdoc} */ |
||
25 | View Code Duplication | public function find(array $identifier) |
|
36 | |||
37 | /** {@inheritdoc} */ |
||
38 | public function search(array $criteria = [], array $orderBy = null, $limit = null, $offset = null) |
||
49 | |||
50 | /** |
||
51 | * @param array $criteria |
||
52 | * |
||
53 | * @return RpcRequestInterface |
||
54 | */ |
||
55 | abstract protected function createCountRequest(array $criteria = []); |
||
56 | |||
57 | /** |
||
58 | * @param array $identifier |
||
59 | * |
||
60 | * @return RpcRequestInterface |
||
61 | */ |
||
62 | abstract protected function createFindRequest(array $identifier); |
||
63 | |||
64 | /** |
||
65 | * @param array $criteria |
||
66 | * @param array|null $orderBy |
||
67 | * @param int|null $limit |
||
68 | * @param int|null $offset |
||
69 | * |
||
70 | * @return RpcRequestInterface |
||
71 | */ |
||
72 | abstract protected function createSearchRequest( |
||
78 | } |
||
79 |
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.