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 if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
||
15 | class EE_Request |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @access private |
||
20 | * @var array $_get $_GET parameters |
||
21 | */ |
||
22 | private $_get = array(); |
||
23 | |||
24 | /** |
||
25 | * @access private |
||
26 | * @var array $_post $_POST parameters |
||
27 | */ |
||
28 | private $_post = array(); |
||
29 | |||
30 | /** |
||
31 | * @access private |
||
32 | * @var array $_cookie $_COOKIE parameters |
||
33 | */ |
||
34 | private $_cookie = array(); |
||
35 | |||
36 | /** |
||
37 | * @access private |
||
38 | * @var array $_params $_REQUEST parameters |
||
39 | */ |
||
40 | private $_params = array(); |
||
41 | |||
42 | /** |
||
43 | * whether current request is via AJAX |
||
44 | * |
||
45 | * @var boolean |
||
46 | * @access public |
||
47 | */ |
||
48 | public $ajax = false; |
||
49 | |||
50 | /** |
||
51 | * whether current request is via AJAX from the frontend of the site |
||
52 | * |
||
53 | * @var boolean |
||
54 | * @access public |
||
55 | */ |
||
56 | public $front_ajax = false; |
||
57 | |||
58 | /** |
||
59 | * IP address for request |
||
60 | * |
||
61 | * @var string $_ip_address |
||
62 | */ |
||
63 | private $_ip_address = ''; |
||
64 | |||
65 | |||
66 | |||
67 | /** |
||
68 | * class constructor |
||
69 | * |
||
70 | * @access public |
||
71 | * @param array $get |
||
72 | * @param array $post |
||
73 | * @param array $cookie |
||
74 | */ |
||
75 | public function __construct($get, $post, $cookie) |
||
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * @return array |
||
93 | */ |
||
94 | public function get_params() |
||
98 | |||
99 | |||
100 | |||
101 | /** |
||
102 | * @return array |
||
103 | */ |
||
104 | public function post_params() |
||
108 | |||
109 | |||
110 | |||
111 | /** |
||
112 | * @return array |
||
113 | */ |
||
114 | public function cookie_params() |
||
118 | |||
119 | |||
120 | |||
121 | /** |
||
122 | * returns contents of $_REQUEST |
||
123 | * |
||
124 | * @return array |
||
125 | */ |
||
126 | public function params() |
||
130 | |||
131 | |||
132 | |||
133 | /** |
||
134 | * setter |
||
135 | * |
||
136 | * @access public |
||
137 | * @param $key |
||
138 | * @param $value |
||
139 | * @param bool $override_ee |
||
140 | * @return void |
||
141 | */ |
||
142 | View Code Duplication | public function set($key, $value, $override_ee = false) |
|
153 | |||
154 | |||
155 | |||
156 | /** |
||
157 | * getter |
||
158 | * |
||
159 | * @access public |
||
160 | * @param $key |
||
161 | * @param null $default |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function get($key, $default = null) |
||
168 | |||
169 | |||
170 | |||
171 | /** |
||
172 | * check if param exists |
||
173 | * |
||
174 | * @access public |
||
175 | * @param $key |
||
176 | * @return boolean |
||
177 | */ |
||
178 | public function is_set($key) |
||
182 | |||
183 | |||
184 | |||
185 | /** |
||
186 | * remove param |
||
187 | * |
||
188 | * @access public |
||
189 | * @param $key |
||
190 | * @param bool $unset_from_global_too |
||
191 | */ |
||
192 | public function un_set($key, $unset_from_global_too = false) |
||
199 | |||
200 | |||
201 | |||
202 | /** |
||
203 | * @return string |
||
204 | */ |
||
205 | public function ip_address() |
||
209 | |||
210 | |||
211 | |||
212 | /** |
||
213 | * _visitor_ip |
||
214 | * attempt to get IP address of current visitor from server |
||
215 | * plz see: http://stackoverflow.com/a/2031935/1475279 |
||
216 | * |
||
217 | * @access public |
||
218 | * @return string |
||
219 | */ |
||
220 | View Code Duplication | private function _visitor_ip() |
|
243 | |||
244 | |||
245 | |||
246 | } |
||
247 | // End of file EE_Request.core.php |
||
248 | // Location: /core/request_stack/EE_Request.core.php |
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.