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')) exit('No direct script access allowed'); |
||
11 | class EE_Request { |
||
12 | |||
13 | /** |
||
14 | * @access private |
||
15 | * @var array $_get $_GET parameters |
||
16 | */ |
||
17 | private $_get = array(); |
||
18 | |||
19 | /** |
||
20 | * @access private |
||
21 | * @var array $_post $_POST parameters |
||
22 | */ |
||
23 | private $_post = array(); |
||
24 | |||
25 | /** |
||
26 | * @access private |
||
27 | * @var array $_cookie $_COOKIE parameters |
||
28 | */ |
||
29 | private $_cookie = array(); |
||
30 | |||
31 | /** |
||
32 | * @access private |
||
33 | * @var array $_params $_REQUEST parameters |
||
34 | */ |
||
35 | private $_params = array(); |
||
36 | |||
37 | /** |
||
38 | * whether current request is via AJAX |
||
39 | * |
||
40 | * @var boolean |
||
41 | * @access public |
||
42 | */ |
||
43 | public $ajax = false; |
||
44 | |||
45 | /** |
||
46 | * whether current request is via AJAX from the frontend of the site |
||
47 | * |
||
48 | * @var boolean |
||
49 | * @access public |
||
50 | */ |
||
51 | public $front_ajax = false; |
||
52 | |||
53 | |||
54 | |||
55 | /** |
||
56 | * class constructor |
||
57 | * |
||
58 | * @access public |
||
59 | * @param array $get |
||
60 | * @param array $post |
||
61 | * @param array $cookie |
||
62 | */ |
||
63 | public function __construct( $get, $post, $cookie ) { |
||
73 | |||
74 | |||
75 | |||
76 | /** |
||
77 | * @return array |
||
78 | */ |
||
79 | public function get_params() { |
||
82 | |||
83 | |||
84 | |||
85 | /** |
||
86 | * @return array |
||
87 | */ |
||
88 | public function post_params() { |
||
91 | |||
92 | |||
93 | |||
94 | /** |
||
95 | * @return array |
||
96 | */ |
||
97 | public function cookie_params() { |
||
100 | |||
101 | |||
102 | |||
103 | /** |
||
104 | * returns contents of $_REQUEST |
||
105 | * @return array |
||
106 | */ |
||
107 | public function params() { |
||
110 | |||
111 | |||
112 | |||
113 | /** |
||
114 | * setter |
||
115 | * |
||
116 | * @access public |
||
117 | * @param $key |
||
118 | * @param $value |
||
119 | * @param bool $override_ee |
||
120 | * @return void |
||
121 | */ |
||
122 | public function set( $key, $value, $override_ee = FALSE ) { |
||
128 | |||
129 | |||
130 | |||
131 | /** |
||
132 | * getter |
||
133 | * |
||
134 | * @access public |
||
135 | * @param $key |
||
136 | * @param null $default |
||
137 | * @return mixed |
||
138 | */ |
||
139 | public function get( $key, $default = NULL ) { |
||
142 | |||
143 | |||
144 | |||
145 | /** |
||
146 | * check if param exists |
||
147 | * |
||
148 | * @access public |
||
149 | * @param $key |
||
150 | * @return boolean |
||
151 | */ |
||
152 | public function is_set( $key ) { |
||
155 | |||
156 | |||
157 | |||
158 | /** |
||
159 | * remove param |
||
160 | * |
||
161 | * @access public |
||
162 | * @param $key |
||
163 | * @param bool $unset_from_global_too |
||
164 | */ |
||
165 | public function un_set( $key, $unset_from_global_too = false ) { |
||
171 | |||
172 | |||
173 | |||
174 | |||
175 | } |
||
176 | // End of file EE_Request.core.php |
||
177 | // 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.