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 |
||
22 | class Read implements Action, ActionGet |
||
23 | { |
||
24 | use ConstructorUrl, QueryBuilder, AuthenticationHelper; |
||
25 | |||
26 | protected $kernel; |
||
27 | |||
28 | /** |
||
29 | * Type HTTP_TYPE select |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $HTTP_TYPE = 'GET'; |
||
33 | |||
34 | protected $url = '?'; |
||
35 | |||
36 | /** |
||
37 | * @param KernelBpm $bpm |
||
38 | * @return void |
||
39 | */ |
||
40 | 1 | public function injectionKernel(KernelBpm $bpm) |
|
44 | |||
45 | /** |
||
46 | * @return string url |
||
47 | */ |
||
48 | 8 | public function getUrl() |
|
52 | |||
53 | /** |
||
54 | * @return Handler |
||
55 | */ |
||
56 | 1 | public function processData() |
|
61 | |||
62 | 1 | public function getData() |
|
66 | |||
67 | /** |
||
68 | * Request the type of filter |
||
69 | * Design filterConstructor allows you to build logical expressions the conditions selecting the desired object . |
||
70 | * Expressions filterConstructor can be used to reference the properties and literals , |
||
71 | * as well as strings, numbers and Boolean expressions (true, false). |
||
72 | * Expressions $ filter supports arithmetic , logical operations , and operations groups , |
||
73 | * strings , date and time of the operation. |
||
74 | * @documentation |
||
75 | * @param $strRequest |
||
76 | * @return $this |
||
77 | */ |
||
78 | 2 | public function filterConstructor($strRequest) |
|
85 | |||
86 | /** |
||
87 | * Service resources can be obtained in the form of sort . |
||
88 | * asc ascending |
||
89 | * desc descending |
||
90 | * @param string $whatSort |
||
91 | * @param string $param asc | desc |
||
92 | * @return $this |
||
93 | * @throws \Exception |
||
94 | */ |
||
95 | 2 | public function orderBy($whatSort, $param = 'asc') |
|
110 | |||
111 | /** |
||
112 | * In bpm'online support the use of parameter $ the skip , |
||
113 | * which allows you to query the service resources , |
||
114 | * skipping the specified number of entries. |
||
115 | * @param $skip |
||
116 | * @return $this |
||
117 | */ |
||
118 | 2 | public function skip($skip) |
|
126 | |||
127 | /** |
||
128 | * Restrictions in the sample query |
||
129 | * If you want the request to return more than 40 records at a time, it can be implemented using the parameter $ top |
||
130 | * @param $amountMax |
||
131 | * @return $this |
||
132 | */ |
||
133 | 2 | public function amount($amountMax = null) |
|
140 | |||
141 | /** |
||
142 | * The number of records |
||
143 | * example SomeCollection/$count or SomeCollection/$count?$filter=... |
||
144 | * @return $this |
||
145 | */ |
||
146 | 1 | public function count() |
|
153 | |||
154 | /** |
||
155 | * TODO Requires refactoring of this method |
||
156 | * @return void |
||
157 | */ |
||
158 | 1 | View Code Duplication | private function query() |
173 | } |
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.