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'); |
||
27 | class EEM_Question extends EEM_Soft_Delete_Base { |
||
28 | |||
29 | // constant used to indicate that the question type is COUNTRY |
||
30 | const QST_type_country = 'COUNTRY'; |
||
31 | |||
32 | // constant used to indicate that the question type is DATE |
||
33 | const QST_type_date = 'DATE'; |
||
34 | |||
35 | // constant used to indicate that the question type is DROPDOWN |
||
36 | const QST_type_dropdown = 'DROPDOWN'; |
||
37 | |||
38 | // constant used to indicate that the question type is CHECKBOX |
||
39 | const QST_type_checkbox = 'CHECKBOX'; |
||
40 | |||
41 | // constant used to indicate that the question type is RADIO_BTN |
||
42 | const QST_type_radio = 'RADIO_BTN'; |
||
43 | |||
44 | // constant used to indicate that the question type is STATE |
||
45 | const QST_type_state = 'STATE'; |
||
46 | |||
47 | // constant used to indicate that the question type is TEXT |
||
48 | const QST_type_text = 'TEXT'; |
||
49 | |||
50 | // constant used to indicate that the question type is TEXTAREA |
||
51 | const QST_type_textarea = 'TEXTAREA'; |
||
52 | |||
53 | // constant used to indicate that the question type is a TEXTAREA that allows simple html |
||
54 | const QST_type_html_textarea = 'HTML_TEXTAREA'; |
||
55 | /** |
||
56 | * Question types that are interchangeable, even after answers have been provided for them. |
||
57 | * Top-level keys are category slugs, next level is an array of question types. If question types |
||
58 | * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
||
59 | * @var array |
||
60 | */ |
||
61 | protected $_question_type_categories = null; |
||
62 | /** |
||
63 | * lists all the question types which should be allowed. Ideally, this will be extensible. |
||
64 | * @access private |
||
65 | * @var array of strings |
||
66 | */ |
||
67 | protected $_allowed_question_types; |
||
68 | |||
69 | // private instance of the Attendee object |
||
70 | protected static $_instance = NULL; |
||
71 | |||
72 | protected function __construct( $timezone = NULL ) { |
||
138 | |||
139 | /** |
||
140 | * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
||
141 | * but they can be extended |
||
142 | * @return string[] |
||
143 | */ |
||
144 | public function allowed_question_types(){ |
||
147 | /** |
||
148 | * Gets all the question types in the same category |
||
149 | * @param string $question_type one of EEM_Question::allowed_question_types( |
||
150 | * @return string[] like EEM_Question::allowed_question_types() |
||
151 | */ |
||
152 | public function question_types_in_same_category( $question_type ) { |
||
163 | |||
164 | /** |
||
165 | * Determines if the given question type is in the given question type category |
||
166 | * @param string $question_type one of EEM_Question::allowed_question_types() |
||
167 | * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
||
168 | * @return boolean |
||
169 | */ |
||
170 | public function question_type_is_in_category( $question_type, $category ) { |
||
176 | |||
177 | /** |
||
178 | * Returns the question type categories 2d array |
||
179 | * @return array see EEM_Question::_question_type_categories |
||
180 | */ |
||
181 | public function question_type_categories() { |
||
184 | |||
185 | /** |
||
186 | * Returns an array of all the QST_system values that can be allowed in the system question group |
||
187 | * identified by $system_question_group_id |
||
188 | * @param string $system_question_group_id QSG_system |
||
189 | * @return array of system question names (QST_system) |
||
190 | */ |
||
191 | public function allowed_system_questions_in_system_question_group( $system_question_group_id ) { |
||
216 | |||
217 | /** |
||
218 | * Returns an array of all the QST_system values that are required in the system question group |
||
219 | * identified by $system_question_group_id |
||
220 | * @param string $system_question_group_id QSG_system |
||
221 | * @return array of system question names (QST_system) |
||
222 | */ |
||
223 | public function required_system_questions_in_system_question_group( $system_question_group_id ) { |
||
237 | |||
238 | |||
239 | |||
240 | /** |
||
241 | * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
||
242 | * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
||
243 | * @param $QST_system |
||
244 | * @return int of QST_ID for the question that corresponds to that QST_system |
||
245 | */ |
||
246 | public function get_Question_ID_from_system_string( $QST_system ){ |
||
249 | |||
250 | |||
251 | |||
252 | /** |
||
253 | * searches the db for the question with the latest question order and returns that value. |
||
254 | * @access public |
||
255 | * @return int |
||
256 | */ |
||
257 | View Code Duplication | public function get_latest_question_order() { |
|
264 | |||
265 | /** |
||
266 | * Returns an array where keys are system question QST_system values, |
||
267 | * and values are the highest question max the admin can set on the question |
||
268 | * (aka the "max max"; eg, a site admin can change the zip question to have a max |
||
269 | * of 5, but no larger than 12) |
||
270 | * @return array |
||
271 | */ |
||
272 | public function system_question_maxes() { |
||
284 | |||
285 | /** |
||
286 | * Given a QST_system value, gets the question's largest allowable max input. |
||
287 | * See Registraiton_Form_Admin_Page::system_question_maxes() |
||
288 | * @param string $system_question_value |
||
289 | * @return int|float |
||
290 | */ |
||
291 | public function max_max_for_system_question( $system_question_value ) { |
||
299 | |||
300 | |||
301 | |||
302 | |||
303 | |||
304 | } |
||
305 | // End of file EEM_Question.model.php |
||
307 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..