| Conditions | 20 |
| Paths | 17169 |
| Total Lines | 100 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 34 | public function search(Search_SearchQuery $query, Search_SearchResults $search_results) { |
||
| 35 | include_once('www/tracker/include/ArtifactTypeHtml.class.php'); |
||
| 36 | include_once('www/tracker/include/ArtifactHtml.class.php'); |
||
| 37 | |||
| 38 | $project = $query->getProject(); |
||
| 39 | if ($project->isError()) { |
||
| 40 | return; |
||
| 41 | } |
||
| 42 | $group_id = $project->getId(); |
||
| 43 | $words = $query->getWords(); |
||
| 44 | $exact = $query->getExact(); |
||
| 45 | $offset = $query->getOffset(); |
||
| 46 | $atid = $query->getTrackerV3Id(); |
||
| 47 | |||
| 48 | ob_start(); |
||
| 49 | // |
||
| 50 | // Create the ArtifactType object |
||
| 51 | // |
||
| 52 | $ath = new ArtifactTypeHtml($project, $atid); |
||
| 53 | if (!$ath || !is_object($ath)) { |
||
| 54 | exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error')); |
||
| 55 | } |
||
| 56 | if ($ath->isError()) { |
||
| 57 | exit_error($GLOBALS['Language']->getText('global', 'error'), $ath->getErrorMessage()); |
||
| 58 | } |
||
| 59 | // Check if this tracker is valid (not deleted) |
||
| 60 | if (!$ath->isValid()) { |
||
| 61 | exit_error($GLOBALS['Language']->getText('global', 'error'), $GLOBALS['Language']->getText('global', 'error')); |
||
| 62 | } |
||
| 63 | |||
| 64 | $results = $this->dao->searchGlobalPaginated($words, $exact, $offset, $atid, UserManager::instance()->getCurrentUser()->getUgroups($group_id, $atid), $query->getNumberOfResults()); |
||
| 65 | $rows_returned = $this->dao->foundRows(); |
||
| 66 | |||
| 67 | $art_displayed = 0; |
||
| 68 | if ($rows_returned < 1) { |
||
| 69 | echo '<H2>' . $GLOBALS['Language']->getText('search_index', 'no_match_found', htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8')) . '</H2>'; |
||
| 70 | } else { |
||
| 71 | // Create field factory |
||
| 72 | $art_field_fact = new ArtifactFieldFactory($ath); |
||
| 73 | |||
| 74 | echo '<H3>' . $GLOBALS['Language']->getText('search_index', 'search_res', array(htmlentities(stripslashes($words), ENT_QUOTES, 'UTF-8'), $rows_returned)) . "</H3><P>\n"; |
||
| 75 | |||
| 76 | $title_arr = array(); |
||
| 77 | |||
| 78 | $summary_field = $art_field_fact->getFieldFromName("summary"); |
||
| 79 | if ($summary_field->userCanRead($group_id, $atid)) |
||
| 80 | $title_arr[] = $GLOBALS['Language']->getText('search_index', 'artifact_summary'); |
||
| 81 | $submitted_field = $art_field_fact->getFieldFromName("submitted_by"); |
||
| 82 | if ($submitted_field->userCanRead($group_id, $atid)) |
||
| 83 | $title_arr[] = $GLOBALS['Language']->getText('search_index', 'submitted_by'); |
||
| 84 | $date_field = $art_field_fact->getFieldFromName("open_date"); |
||
| 85 | if ($date_field->userCanRead($group_id, $atid)) |
||
| 86 | $title_arr[] = $GLOBALS['Language']->getText('search_index', 'date'); |
||
| 87 | $status_field = $art_field_fact->getFieldFromName("status_id"); |
||
| 88 | if ($status_field->userCanRead($group_id, $atid)) |
||
| 89 | $title_arr[] = $GLOBALS['Language']->getText('global', 'status'); |
||
| 90 | |||
| 91 | echo html_build_list_table_top($title_arr); |
||
| 92 | |||
| 93 | echo "\n"; |
||
| 94 | |||
| 95 | |||
| 96 | $rows = 0; |
||
| 97 | foreach ($results as $arr) { |
||
|
|
|||
| 98 | $rows++; |
||
| 99 | $curArtifact = new Artifact($ath, $arr['artifact_id']); |
||
| 100 | if ($curArtifact->isStatusClosed($curArtifact->getStatusID())) { |
||
| 101 | $status = $GLOBALS['Language']->getText('global', 'closed'); |
||
| 102 | } else { |
||
| 103 | $status = $GLOBALS['Language']->getText('global', 'open'); |
||
| 104 | } |
||
| 105 | // Only display artifacts that the user is allowed to see |
||
| 106 | if ($curArtifact->userCanView(user_getid())) { |
||
| 107 | print "\n<TR class=\"" . html_get_alt_row_color($art_displayed) . "\">"; |
||
| 108 | if ($summary_field->userCanRead($group_id, $atid)) |
||
| 109 | print "<TD><A HREF=\"/tracker/?group_id=$group_id&func=detail&atid=$atid&aid=" |
||
| 110 | . $arr['artifact_id'] . "\"><IMG SRC=\"" . util_get_image_theme('msg.png') . "\" BORDER=0 HEIGHT=12 WIDTH=10> " |
||
| 111 | . $arr['summary'] . "</A></TD>"; |
||
| 112 | if ($submitted_field->userCanRead($group_id, $atid)) |
||
| 113 | print "<TD>" . $arr['user_name'] . "</TD>"; |
||
| 114 | if ($date_field->userCanRead($group_id, $atid)) |
||
| 115 | print "<TD>" . format_date($GLOBALS['Language']->getText('system', 'datefmt'), $arr['open_date']) . "</TD>"; |
||
| 116 | if ($status_field->userCanRead($group_id, $atid)) |
||
| 117 | print "<TD>" . $status . "</TD>"; |
||
| 118 | print "</TR>"; |
||
| 119 | $art_displayed++; |
||
| 120 | if ($art_displayed > $query->getNumberOfResults()) { |
||
| 121 | break; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | echo "</TABLE>\n"; |
||
| 126 | } |
||
| 127 | |||
| 128 | $maybe_more_results = ($art_displayed < $query->getNumberOfResults()) ? false : true; |
||
| 129 | $search_results->setCountResults($art_displayed) |
||
| 130 | ->setHasMore($maybe_more_results); |
||
| 131 | |||
| 132 | return new Search_SearchTrackerV3ResultPresenter(ob_get_clean()); |
||
| 133 | } |
||
| 134 | |||
| 162 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.