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 | // constant used to indicate that the question type is an email input |
||
57 | const QST_type_email = 'EMAIL'; |
||
58 | |||
59 | // constant used to indicate that the question type is a US-formatted phone number |
||
60 | const QST_type_us_phone = 'US_PHONE'; |
||
61 | |||
62 | // constant used to indicate that the question type is an integer (whole number) |
||
63 | const QST_type_int = 'INTEGER'; |
||
64 | |||
65 | // constant used to indicate that the question type is a decimal (float) |
||
66 | const QST_type_decimal = 'DECIMAL'; |
||
67 | |||
68 | // constant used to indicate that the question type is a valid URL |
||
69 | const QST_type_url = 'URL'; |
||
70 | |||
71 | // constant used to indicate that the question type is a YEAR |
||
72 | const QST_type_year = 'YEAR'; |
||
73 | |||
74 | // constant used to indicate that the question type is a multi-select |
||
75 | const QST_type_multi_select = 'MULTI_SELECT'; |
||
76 | |||
77 | /** |
||
78 | * Question types that are interchangeable, even after answers have been provided for them. |
||
79 | * Top-level keys are category slugs, next level is an array of question types. If question types |
||
80 | * aren't in this array, it is assumed they AREN'T interchangeable with any other question types. |
||
81 | * @var array |
||
82 | */ |
||
83 | protected $_question_type_categories = null; |
||
84 | |||
85 | /** |
||
86 | * lists all the question types which should be allowed. Ideally, this will be extensible. |
||
87 | * @access private |
||
88 | * @var array of strings |
||
89 | */ |
||
90 | protected $_allowed_question_types; |
||
91 | |||
92 | /** |
||
93 | * brief descriptions for all the question types |
||
94 | * @access private |
||
95 | * @var array of strings |
||
96 | */ |
||
97 | protected $_question_descriptions; |
||
98 | |||
99 | |||
100 | // private instance of the Attendee object |
||
101 | protected static $_instance = NULL; |
||
102 | |||
103 | |||
104 | |||
105 | /** |
||
106 | * EEM_Question constructor. |
||
107 | * |
||
108 | * @param null $timezone |
||
109 | */ |
||
110 | protected function __construct( $timezone = NULL ) { |
||
213 | |||
214 | /** |
||
215 | * Returns the list of allowed question types, which are normally: 'TEXT','TEXTAREA','RADIO_BTN','DROPDOWN','CHECKBOX','DATE' |
||
216 | * but they can be extended |
||
217 | * @return string[] |
||
218 | */ |
||
219 | public function allowed_question_types(){ |
||
222 | /** |
||
223 | * Gets all the question types in the same category |
||
224 | * @param string $question_type one of EEM_Question::allowed_question_types( |
||
225 | * @return string[] like EEM_Question::allowed_question_types() |
||
226 | */ |
||
227 | public function question_types_in_same_category( $question_type ) { |
||
238 | |||
239 | /** |
||
240 | * Determines if the given question type is in the given question type category |
||
241 | * @param string $question_type one of EEM_Question::allowed_question_types() |
||
242 | * @param string $category one of the top-level keys of EEM_Question::question_type_categories() |
||
243 | * @return boolean |
||
244 | */ |
||
245 | public function question_type_is_in_category( $question_type, $category ) { |
||
251 | |||
252 | /** |
||
253 | * Returns the question type categories 2d array |
||
254 | * @return array see EEM_Question::_question_type_categories |
||
255 | */ |
||
256 | public function question_type_categories() { |
||
259 | |||
260 | /** |
||
261 | * Returns an array of all the QST_system values that can be allowed in the system question group |
||
262 | * identified by $system_question_group_id |
||
263 | * @param string $system_question_group_id QSG_system |
||
264 | * @return array of system question names (QST_system) |
||
265 | */ |
||
266 | public function allowed_system_questions_in_system_question_group( $system_question_group_id ) { |
||
291 | |||
292 | /** |
||
293 | * Returns an array of all the QST_system values that are required in the system question group |
||
294 | * identified by $system_question_group_id |
||
295 | * @param string $system_question_group_id QSG_system |
||
296 | * @return array of system question names (QST_system) |
||
297 | */ |
||
298 | public function required_system_questions_in_system_question_group( $system_question_group_id ) { |
||
312 | |||
313 | |||
314 | |||
315 | /** |
||
316 | * Gets an array for converting between QST_system and QST_IDs for system questions. Eg, if you want to know |
||
317 | * which system question QST_ID corresponds to the QST_system 'city', use EEM_Question::instance()->get_Question_ID_from_system_string('city'); |
||
318 | * @param $QST_system |
||
319 | * @return int of QST_ID for the question that corresponds to that QST_system |
||
320 | */ |
||
321 | public function get_Question_ID_from_system_string( $QST_system ){ |
||
324 | |||
325 | |||
326 | |||
327 | /** |
||
328 | * searches the db for the question with the latest question order and returns that value. |
||
329 | * @access public |
||
330 | * @return int |
||
331 | */ |
||
332 | View Code Duplication | public function get_latest_question_order() { |
|
339 | |||
340 | /** |
||
341 | * Returns an array where keys are system question QST_system values, |
||
342 | * and values are the highest question max the admin can set on the question |
||
343 | * (aka the "max max"; eg, a site admin can change the zip question to have a max |
||
344 | * of 5, but no larger than 12) |
||
345 | * @return array |
||
346 | */ |
||
347 | public function system_question_maxes() { |
||
359 | |||
360 | /** |
||
361 | * Given a QST_system value, gets the question's largest allowable max input. |
||
362 | * @see Registration_Form_Admin_Page::system_question_maxes() |
||
363 | * @param string $system_question_value |
||
364 | * @return int|float |
||
365 | */ |
||
366 | public function absolute_max_for_system_question( $system_question_value ) { |
||
374 | |||
375 | |||
376 | |||
377 | /** |
||
378 | * @return array |
||
379 | */ |
||
380 | public function question_descriptions() { |
||
383 | |||
384 | |||
385 | |||
386 | |||
387 | |||
388 | } |
||
389 | // End of file EEM_Question.model.php |
||
391 |
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..