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:
Complex classes like GradebookUtils often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use GradebookUtils, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | class GradebookUtils |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * Adds a resource to the unique gradebook of a given course |
||
| 11 | * @param int |
||
| 12 | * @param string Course code |
||
| 13 | * @param int Resource type (use constants defined in linkfactory.class.php) |
||
| 14 | * @param int Resource ID in the corresponding tool |
||
| 15 | * @param string Resource name to show in the gradebook |
||
| 16 | * @param int Resource weight to set in the gradebook |
||
| 17 | * @param int Resource max |
||
| 18 | * @param string Resource description |
||
| 19 | * @param int Visibility (0 hidden, 1 shown) |
||
| 20 | * @param int Session ID (optional or 0 if not defined) |
||
| 21 | * @param int |
||
| 22 | * @param integer $resource_type |
||
| 23 | * @return boolean True on success, false on failure |
||
| 24 | */ |
||
| 25 | public static function add_resource_to_course_gradebook( |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Update a resource weight |
||
| 71 | * @param int Link/Resource ID |
||
| 72 | * @param string |
||
| 73 | * @param float |
||
| 74 | * @return bool false on error, true on success |
||
| 75 | */ |
||
| 76 | public static function updateResourceFromCourseGradebook($link_id, $courseId, $weight) |
||
| 77 | { |
||
| 78 | $courseId = (int) $courseId; |
||
| 79 | if (!empty($link_id)) { |
||
| 80 | $link_id = intval($link_id); |
||
| 81 | $sql = 'UPDATE ' . Database :: get_main_table(TABLE_MAIN_GRADEBOOK_LINK) . ' |
||
| 82 | SET weight = ' . "'" . Database::escape_string((float) $weight) . "'" . ' |
||
| 83 | WHERE c_id = "' . $courseId . '" AND id = ' . $link_id; |
||
| 84 | Database::query($sql); |
||
| 85 | } |
||
| 86 | |||
| 87 | return true; |
||
| 88 | } |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Remove a resource from the unique gradebook of a given course |
||
| 92 | * @param int Link/Resource ID |
||
| 93 | * @return bool false on error, true on success |
||
| 94 | */ |
||
| 95 | View Code Duplication | public static function remove_resource_from_course_gradebook($link_id) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * Block students |
||
| 111 | */ |
||
| 112 | public static function block_students() |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Builds an img tag for a gradebook item |
||
| 121 | */ |
||
| 122 | public static function build_type_icon_tag($kind, $attributes = array()) |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Returns the icon filename for a gradebook item |
||
| 129 | * @param string $type value returned by a gradebookitem's get_icon_name() |
||
| 130 | */ |
||
| 131 | public static function get_icon_file_name($type) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * Builds the course or platform admin icons to edit a category |
||
| 184 | * @param Category $cat category |
||
| 185 | * @param Category $selectcat id of selected category |
||
| 186 | */ |
||
| 187 | public static function build_edit_icons_cat($cat, $selectcat) |
||
| 188 | { |
||
| 189 | $show_message = $cat->show_message_resource_delete($cat->get_course_code()); |
||
| 190 | $grade_model_id = $selectcat->get_grade_model_id(); |
||
| 191 | $selectcat = $selectcat->get_id(); |
||
| 192 | $modify_icons = null; |
||
| 193 | |||
| 194 | if ($show_message === false) { |
||
| 195 | $visibility_icon = ($cat->is_visible() == 0) ? 'invisible' : 'visible'; |
||
| 196 | $visibility_command = ($cat->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||
| 197 | |||
| 198 | $modify_icons .= '<a class="view_children" data-cat-id="' . $cat->get_id() . '" href="javascript:void(0);">' . |
||
| 199 | Display::return_icon('view_more_stats.gif', get_lang('Show'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 200 | |||
| 201 | if (!api_is_allowed_to_edit(null, true)) { |
||
| 202 | $modify_icons .= Display::url( |
||
| 203 | Display::return_icon( |
||
| 204 | 'stats.png', |
||
| 205 | get_lang('FlatView'), |
||
| 206 | '', |
||
| 207 | ICON_SIZE_SMALL |
||
| 208 | ), |
||
| 209 | 'personal_stats.php?' . http_build_query([ |
||
| 210 | 'selectcat' => $cat->get_id() |
||
| 211 | ]) . '&' . api_get_cidreq(), |
||
| 212 | [ |
||
| 213 | 'class' => 'ajax', |
||
| 214 | 'data-title' => get_lang('FlatView') |
||
| 215 | ] |
||
| 216 | ); |
||
| 217 | } |
||
| 218 | |||
| 219 | $courseParams = api_get_cidreq_params($cat->get_course_code(), $cat->get_session_id()); |
||
| 220 | |||
| 221 | if (api_is_allowed_to_edit(null, true)) { |
||
| 222 | // Locking button |
||
| 223 | if (api_get_setting('gradebook_locking_enabled') == 'true') { |
||
| 224 | if ($cat->is_locked()) { |
||
| 225 | View Code Duplication | if (api_is_platform_admin()) { |
|
| 226 | $modify_icons .= ' <a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToUnlockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=unlock">' . |
||
| 227 | Display::return_icon('lock.png', get_lang('UnLockEvaluation'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 228 | } else { |
||
| 229 | $modify_icons .= ' <a href="#">' . Display::return_icon('lock_na.png', get_lang('GradebookLockedAlert'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 230 | } |
||
| 231 | $modify_icons .= ' <a href="gradebook_flatview.php?export_pdf=category&selectcat=' . $cat->get_id() . '" >' . Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 232 | View Code Duplication | } else { |
|
| 233 | $modify_icons .= ' <a onclick="javascript:if (!confirm(\'' . addslashes(get_lang('ConfirmToLockElement')) . '\')) return false;" href="' . api_get_self() . '?' . api_get_cidreq() . '&category_id=' . $cat->get_id() . '&action=lock">' . |
||
| 234 | Display::return_icon('unlock.png', get_lang('LockEvaluation'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 235 | $modify_icons .= ' <a href="#" >' . Display::return_icon('pdf_na.png', get_lang('ExportToPDF'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | if (empty($grade_model_id) || $grade_model_id == -1) { |
||
| 240 | if ($cat->is_locked() && !api_is_platform_admin()) { |
||
| 241 | $modify_icons .= Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL); |
||
| 242 | } else { |
||
| 243 | $modify_icons .= '<a href="gradebook_edit_cat.php?editcat=' . $cat->get_id() . '&'.$courseParams.'">' . |
||
| 244 | Display::return_icon( |
||
| 245 | 'edit.png', |
||
| 246 | get_lang('Modify'), |
||
| 247 | '', |
||
| 248 | ICON_SIZE_SMALL |
||
| 249 | ) . '</a>'; |
||
| 250 | } |
||
| 251 | } |
||
| 252 | |||
| 253 | $modify_icons .= '<a href="gradebook_edit_all.php?selectcat=' .$cat->get_id() . '&' . $courseParams.'">' . |
||
| 254 | Display::return_icon( |
||
| 255 | 'percentage.png', |
||
| 256 | get_lang('EditAllWeights'), |
||
| 257 | '', |
||
| 258 | ICON_SIZE_SMALL |
||
| 259 | ) . '</a>'; |
||
| 260 | |||
| 261 | $modify_icons .= '<a href="gradebook_flatview.php?selectcat=' .$cat->get_id() . '&' . $courseParams. '">' . |
||
| 262 | Display::return_icon( |
||
| 263 | 'stats.png', |
||
| 264 | get_lang('FlatView'), |
||
| 265 | '', |
||
| 266 | ICON_SIZE_SMALL |
||
| 267 | ) . '</a>'; |
||
| 268 | $modify_icons .= ' <a href="' . api_get_self() .'?visiblecat=' . $cat->get_id() . '&' .$visibility_command . '=&selectcat=' . $selectcat .'&' . $courseParams. '">' . |
||
| 269 | Display::return_icon( |
||
| 270 | $visibility_icon . '.png', |
||
| 271 | get_lang('Visible'), |
||
| 272 | '', |
||
| 273 | ICON_SIZE_SMALL |
||
| 274 | ) . '</a>'; |
||
| 275 | |||
| 276 | if ($cat->is_locked() && !api_is_platform_admin()) { |
||
| 277 | $modify_icons .= Display::return_icon('delete_na.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL); |
||
| 278 | } else { |
||
| 279 | $modify_icons .= ' <a href="' . api_get_self() . '?deletecat=' . $cat->get_id() . '&selectcat=' . $selectcat . '&' . $courseParams. '" onclick="return confirmation();">' . |
||
| 280 | Display::return_icon('delete.png', get_lang('DeleteAll'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 281 | } |
||
| 282 | } |
||
| 283 | |||
| 284 | return $modify_icons; |
||
| 285 | } |
||
| 286 | } |
||
| 287 | |||
| 288 | /** |
||
| 289 | * Builds the course or platform admin icons to edit an evaluation |
||
| 290 | * @param Evaluation $eval evaluation object |
||
| 291 | * @param int $selectcat id of selected category |
||
| 292 | */ |
||
| 293 | View Code Duplication | public static function build_edit_icons_eval($eval, $selectcat) |
|
| 294 | { |
||
| 295 | $is_locked = $eval->is_locked(); |
||
| 296 | $eval->get_course_code(); |
||
|
|
|||
| 297 | $cat = new Category(); |
||
| 298 | $message_eval = $cat->show_message_resource_delete($eval->get_course_code()); |
||
| 299 | $courseParams = api_get_cidreq_params($eval->get_course_code(), $eval->getSessionId()); |
||
| 300 | |||
| 301 | if ($message_eval === false && api_is_allowed_to_edit(null, true)) { |
||
| 302 | $visibility_icon = ($eval->is_visible() == 0) ? 'invisible' : 'visible'; |
||
| 303 | $visibility_command = ($eval->is_visible() == 0) ? 'set_visible' : 'set_invisible'; |
||
| 304 | if ($is_locked && !api_is_platform_admin()) { |
||
| 305 | $modify_icons = Display::return_icon('edit_na.png', get_lang('Modify'), '', ICON_SIZE_SMALL); |
||
| 306 | } else { |
||
| 307 | $modify_icons = '<a href="gradebook_edit_eval.php?editeval=' . $eval->get_id() . '&' . $courseParams. '">' . |
||
| 308 | Display::return_icon('edit.png', get_lang('Modify'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 309 | } |
||
| 310 | |||
| 311 | $modify_icons .= ' <a href="' . api_get_self() . '?visibleeval=' . $eval->get_id() . '&' . $visibility_command . '=&selectcat=' . $selectcat . '&'.$courseParams. ' ">' . |
||
| 312 | Display::return_icon($visibility_icon . '.png', get_lang('Visible'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 313 | if (api_is_allowed_to_edit(null, true)) { |
||
| 314 | $modify_icons .= ' <a href="gradebook_showlog_eval.php?visiblelog=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &' . $courseParams. '">' . |
||
| 315 | Display::return_icon('history.png', get_lang('GradebookQualifyLog'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 316 | } |
||
| 317 | |||
| 318 | if ($is_locked && !api_is_platform_admin()) { |
||
| 319 | $modify_icons .= ' ' . Display::return_icon('delete_na.png', get_lang('Delete'), '', ICON_SIZE_SMALL); |
||
| 320 | } else { |
||
| 321 | $modify_icons .= ' <a href="' . api_get_self() . '?deleteeval=' . $eval->get_id() . '&selectcat=' . $selectcat . ' &' . $courseParams. '" onclick="return confirmation();">' . |
||
| 322 | Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL) . '</a>'; |
||
| 323 | } |
||
| 324 | return $modify_icons; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Builds the course or platform admin icons to edit a link |
||
| 330 | * @param AbstractLink $link |
||
| 331 | * @param int $selectcat id of selected category |
||
| 332 | */ |
||
| 333 | View Code Duplication | public static function build_edit_icons_link($link, $selectcat) |
|
| 374 | |||
| 375 | /** |
||
| 376 | * Checks if a resource is in the unique gradebook of a given course |
||
| 377 | * @param int $courseId |
||
| 378 | * @param int $resource_type Resource type (use constants defined in linkfactory.class.php) |
||
| 379 | * @param int $resource_id Resource ID in the corresponding tool |
||
| 380 | * @param int $session_id Session ID (optional - 0 if not defined) |
||
| 381 | * |
||
| 382 | * @return array false on error or array of resource |
||
| 383 | */ |
||
| 384 | public static function isResourceInCourseGradebook($courseId, $resource_type, $resource_id, $session_id = 0) |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Remove a resource from the unique gradebook of a given course |
||
| 405 | * @param int Link/Resource ID |
||
| 406 | * @return bool false on error, true on success |
||
| 407 | */ |
||
| 408 | View Code Duplication | public static function get_resource_from_course_gradebook($link_id) |
|
| 409 | { |
||
| 410 | if (empty($link_id)) { |
||
| 411 | return false; |
||
| 412 | } |
||
| 413 | // TODO find the corresponding category (the first one for this course, ordered by ID) |
||
| 414 | $l = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK); |
||
| 415 | $sql = "SELECT * FROM $l WHERE id = " . (int) $link_id; |
||
| 416 | $res = Database::query($sql); |
||
| 417 | $row = array(); |
||
| 418 | if (Database::num_rows($res) > 0) { |
||
| 419 | $row = Database::fetch_array($res, 'ASSOC'); |
||
| 420 | } |
||
| 421 | return $row; |
||
| 422 | } |
||
| 423 | |||
| 424 | /** |
||
| 425 | * Return the course id |
||
| 426 | * @param int |
||
| 427 | * @return String |
||
| 428 | */ |
||
| 429 | View Code Duplication | public static function get_course_id_by_link_id($id_link) |
|
| 441 | |||
| 442 | /** |
||
| 443 | * @param $type |
||
| 444 | * @return string |
||
| 445 | */ |
||
| 446 | public static function get_table_type_course($type) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @param Category $cat |
||
| 454 | * @param $users |
||
| 455 | * @param $alleval |
||
| 456 | * @param $alllinks |
||
| 457 | * @param $params |
||
| 458 | * @param null $mainCourseCategory |
||
| 459 | * @return array |
||
| 460 | */ |
||
| 461 | public static function get_printable_data($cat, $users, $alleval, $alllinks, $params, $mainCourseCategory = null) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * XML-parser: handle character data |
||
| 500 | */ |
||
| 501 | public static function character_data($parser, $data) |
||
| 506 | |||
| 507 | /** |
||
| 508 | * XML-parser: handle end of element |
||
| 509 | */ |
||
| 510 | public static function element_end($parser, $data) |
||
| 511 | { |
||
| 512 | global $user; |
||
| 513 | global $users; |
||
| 514 | global $current_value; |
||
| 515 | switch ($data) { |
||
| 516 | case 'Result': |
||
| 517 | $users[] = $user; |
||
| 518 | break; |
||
| 519 | default: |
||
| 520 | $user[$data] = $current_value; |
||
| 521 | break; |
||
| 522 | } |
||
| 523 | } |
||
| 524 | |||
| 525 | /** |
||
| 526 | * XML-parser: handle start of element |
||
| 527 | */ |
||
| 528 | public static function element_start($parser, $data) |
||
| 529 | { |
||
| 530 | global $user; |
||
| 531 | global $current_tag; |
||
| 532 | switch ($data) { |
||
| 533 | case 'Result': |
||
| 534 | $user = array(); |
||
| 535 | break; |
||
| 536 | default: |
||
| 537 | $current_tag = $data; |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | public static function overwritescore($resid, $importscore, $eval_max) |
||
| 552 | |||
| 553 | /** |
||
| 554 | * Read the XML-file |
||
| 555 | * @param string $file Path to the XML-file |
||
| 556 | * @return array All user information read from the file |
||
| 557 | */ |
||
| 558 | View Code Duplication | public static function parse_xml_data($file) |
|
| 573 | |||
| 574 | /** |
||
| 575 | * register user info about certificate |
||
| 576 | * @param int $cat_id The category id |
||
| 577 | * @param int $user_id The user id |
||
| 578 | * @param float $score_certificate The score obtained for certified |
||
| 579 | * @param string $date_certificate The date when you obtained the certificate |
||
| 580 | * |
||
| 581 | * @return void |
||
| 582 | */ |
||
| 583 | public static function registerUserInfoAboutCertificate( |
||
| 605 | |||
| 606 | /** |
||
| 607 | * Get date of user certificate |
||
| 608 | * @param int $cat_id The category id |
||
| 609 | * @param int $user_id The user id |
||
| 610 | * @return Datetime The date when you obtained the certificate |
||
| 611 | */ |
||
| 612 | public static function get_certificate_by_user_id($cat_id, $user_id) |
||
| 613 | { |
||
| 614 | $table_certificate = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE); |
||
| 615 | $sql = 'SELECT * FROM ' . $table_certificate . ' |
||
| 616 | WHERE cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '"'; |
||
| 617 | |||
| 618 | $result = Database::query($sql); |
||
| 619 | $row = Database::fetch_array($result, 'ASSOC'); |
||
| 620 | |||
| 621 | return $row; |
||
| 622 | } |
||
| 623 | |||
| 624 | /** |
||
| 625 | * Get list of users certificates |
||
| 626 | * @param int $cat_id The category id |
||
| 627 | * @param array $userList Only users in this list |
||
| 628 | * @return array |
||
| 629 | */ |
||
| 630 | public static function get_list_users_certificates($cat_id = null, $userList = array()) |
||
| 656 | |||
| 657 | /** |
||
| 658 | * Gets the certificate list by user id |
||
| 659 | * @param int $user_id The user id |
||
| 660 | * @param int $cat_id The category id |
||
| 661 | * @return array |
||
| 662 | */ |
||
| 663 | public static function get_list_gradebook_certificates_by_user_id($user_id, $cat_id = null) |
||
| 680 | |||
| 681 | /** |
||
| 682 | * @param int $user_id |
||
| 683 | * @param string $course_code |
||
| 684 | * @param int $sessionId |
||
| 685 | * @param bool $is_preview |
||
| 686 | * @param bool $hide_print_button |
||
| 687 | * |
||
| 688 | * @return array |
||
| 689 | */ |
||
| 690 | public static function get_user_certificate_content($user_id, $course_code, $sessionId, $is_preview = false, $hide_print_button = false) |
||
| 735 | |||
| 736 | /** |
||
| 737 | * @param int $courseId |
||
| 738 | * @param int $gradebook_model_id |
||
| 739 | * @return mixed |
||
| 740 | */ |
||
| 741 | public static function createDefaultCourseGradebook($courseId = 0, $gradebook_model_id = 0) |
||
| 795 | |||
| 796 | /** |
||
| 797 | * @param FormValidator $form |
||
| 798 | */ |
||
| 799 | public static function load_gradebook_select_in_tool($form) |
||
| 830 | |||
| 831 | /** |
||
| 832 | * @param FlatViewTable $flatviewtable |
||
| 833 | * @param Category $cat |
||
| 834 | * @param $users |
||
| 835 | * @param $alleval |
||
| 836 | * @param $alllinks |
||
| 837 | * @param array $params |
||
| 838 | * @param null $mainCourseCategory |
||
| 839 | */ |
||
| 840 | public static function export_pdf_flatview( |
||
| 972 | |||
| 973 | /** |
||
| 974 | * @param string[] $list_values |
||
| 975 | * @return string |
||
| 976 | */ |
||
| 977 | public static function score_badges($list_values) |
||
| 991 | |||
| 992 | /** |
||
| 993 | * returns users within a course given by param |
||
| 994 | * @param string $courseCode |
||
| 995 | */ |
||
| 996 | public static function get_users_in_course($courseCode) |
||
| 1032 | |||
| 1033 | /** |
||
| 1034 | * @param Doctrine\DBAL\Driver\Statement|null $result |
||
| 1035 | * @return array |
||
| 1036 | */ |
||
| 1037 | public static function get_user_array_from_sql_result($result) |
||
| 1053 | |||
| 1054 | /** |
||
| 1055 | * @param array $evals |
||
| 1056 | * @param array $links |
||
| 1057 | * @return array |
||
| 1058 | */ |
||
| 1059 | public static function get_all_users($evals = array(), $links = array()) |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * Search students matching a given last name and/or first name |
||
| 1110 | * @author Bert Steppé |
||
| 1111 | */ |
||
| 1112 | public static function find_students($mask= '') |
||
| 1154 | |||
| 1155 | /** |
||
| 1156 | * @param int $linkId |
||
| 1157 | * @param float $weight |
||
| 1158 | */ |
||
| 1159 | public static function updateLinkWeight($linkId, $name, $weight) |
||
| 1216 | |||
| 1217 | /** |
||
| 1218 | * @param int $id |
||
| 1219 | * @param float $weight |
||
| 1220 | */ |
||
| 1221 | View Code Duplication | public static function updateEvaluationWeight($id, $weight) |
|
| 1232 | |||
| 1233 | /** |
||
| 1234 | * |
||
| 1235 | * Get the achieved certificates for a user in courses |
||
| 1236 | * @param int $userId The user id |
||
| 1237 | * @param bool $includeNonPublicCertificates Whether include the non-plublic certificates |
||
| 1238 | * @return array |
||
| 1239 | */ |
||
| 1240 | public static function getUserCertificatesInCourses($userId, $includeNonPublicCertificates = true) |
||
| 1282 | |||
| 1283 | /** |
||
| 1284 | * Get the achieved certificates for a user in course sessions |
||
| 1285 | * @param int $userId The user id |
||
| 1286 | * @param bool $includeNonPublicCertificates Whether include the non-plublic certificates |
||
| 1287 | * @return array |
||
| 1288 | */ |
||
| 1289 | public static function getUserCertificatesInSessions($userId, $includeNonPublicCertificates = true) |
||
| 1347 | |||
| 1348 | /** |
||
| 1349 | * @param int $userId |
||
| 1350 | * @param array $cats |
||
| 1351 | * @param bool $saveToFile |
||
| 1352 | * @param bool $saveToHtmlFile |
||
| 1353 | * @param array $studentList |
||
| 1354 | * @param PDF $pdf |
||
| 1355 | * |
||
| 1356 | * @return string |
||
| 1357 | */ |
||
| 1358 | public static function generateTable( |
||
| 1460 | } |
||
| 1461 |
PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.
Let’s take a look at an example:
If we look at the
getEmail()method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:On the hand, if we look at the
setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call: