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 |
||
30 | View Code Duplication | abstract class AbstractBulkCreateRequest extends AbstractBaseRequest |
|
|
|||
31 | { |
||
32 | const LINE_BREAK = "\n"; |
||
33 | const REQUEST_ACTION = '_bulk'; |
||
34 | const BULK_ACTION = 'create'; |
||
35 | |||
36 | /** |
||
37 | * @var null|mixed |
||
38 | */ |
||
39 | private $body = null; |
||
40 | |||
41 | /** |
||
42 | * This will overwrite getIndex method for returning null. |
||
43 | * The index property is only for internal use. |
||
44 | * |
||
45 | * @return null |
||
46 | */ |
||
47 | 3 | public function getIndex() |
|
51 | |||
52 | /** |
||
53 | * This will overwrite getType method for returning null. |
||
54 | * The type property is only for internal use. |
||
55 | * |
||
56 | * @return null |
||
57 | */ |
||
58 | 3 | public function getType() |
|
62 | |||
63 | /** |
||
64 | * @inheritdoc |
||
65 | */ |
||
66 | 3 | public function getMethod() |
|
70 | |||
71 | /** |
||
72 | * @inheritdoc |
||
73 | */ |
||
74 | 3 | public function getAction() |
|
78 | |||
79 | /** |
||
80 | * @inheritdoc |
||
81 | */ |
||
82 | 6 | public function getBody() |
|
86 | |||
87 | /** |
||
88 | * @inheritdoc |
||
89 | */ |
||
90 | 3 | public function setBody($body) |
|
94 | |||
95 | /** |
||
96 | * adds a document to the body and transforms it in the right format. |
||
97 | * |
||
98 | * @param array|object $doc |
||
99 | * @param string $id |
||
100 | * @author Daniel Wendlandt |
||
101 | */ |
||
102 | 3 | public function addDocument($doc, $id = null) |
|
115 | } |
||
116 |
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.