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 | * @type array $_params $_REQUEST parameters |
||
16 | */ |
||
17 | private $_params = array(); |
||
18 | |||
19 | /** |
||
20 | * whether current request is via AJAX |
||
21 | * @type boolean |
||
22 | * @access public |
||
23 | */ |
||
24 | public $ajax = FALSE; |
||
25 | |||
26 | /** |
||
27 | * whether current request is via AJAX from the frontend of the site |
||
28 | * @type boolean |
||
29 | * @access public |
||
30 | */ |
||
31 | public $front_ajax = FALSE; |
||
32 | |||
33 | |||
34 | |||
35 | /** |
||
36 | * class constructor |
||
37 | * |
||
38 | * @access public |
||
39 | * @param array $request |
||
40 | */ |
||
41 | public function __construct( $request ) { |
||
48 | |||
49 | |||
50 | |||
51 | /** |
||
52 | * returns contents of $_REQUEST |
||
53 | * @return array |
||
54 | */ |
||
55 | public function params() { |
||
58 | |||
59 | |||
60 | |||
61 | /** |
||
62 | * setter |
||
63 | * |
||
64 | * @access public |
||
65 | * @param $key |
||
66 | * @param $value |
||
67 | * @param bool $override_ee |
||
68 | * @return void |
||
69 | */ |
||
70 | public function set( $key, $value, $override_ee = FALSE ) { |
||
71 | // don't allow "ee" to be overwritten unless explicitly instructed to do so |
||
72 | View Code Duplication | if ( $key != 'ee' || ( $key == 'ee' && empty( $this->_params['ee'] )) || ( $key == 'ee' && ! empty( $this->_params['ee'] ) && $override_ee )) { |
|
|
|||
73 | $this->_params[ $key ] = $value; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | |||
78 | |||
79 | /** |
||
80 | * getter |
||
81 | * |
||
82 | * @access public |
||
83 | * @param $key |
||
84 | * @param null $default |
||
85 | * @return mixed |
||
86 | */ |
||
87 | public function get( $key, $default = NULL ) { |
||
90 | |||
91 | |||
92 | |||
93 | /** |
||
94 | * check if param exists |
||
95 | * |
||
96 | * @access public |
||
97 | * @param $key |
||
98 | * @return boolean |
||
99 | */ |
||
100 | public function is_set( $key ) { |
||
103 | |||
104 | |||
105 | |||
106 | /** |
||
107 | * remove param |
||
108 | * |
||
109 | * @access public |
||
110 | * @param $key |
||
111 | * @param bool $unset_from_global_too |
||
112 | */ |
||
113 | public function un_set( $key, $unset_from_global_too = false ) { |
||
119 | |||
120 | |||
121 | |||
122 | |||
123 | } |
||
124 | // End of file EE_Request.core.php |
||
125 | // 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.