Conditions | 25 |
Paths | 39 |
Total Lines | 96 |
Code Lines | 74 |
Lines | 0 |
Ratio | 0 % |
Changes | 6 | ||
Bugs | 2 | Features | 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 |
||
89 | public function search($search_entryid, $search_patterns, $folder_entryid, $recursive) { |
||
90 | $whereFolderids = ''; |
||
91 | if (isset($folder_entryid)) { |
||
92 | try { |
||
93 | $folder = mapi_msgstore_openentry($this->store, $folder_entryid); |
||
94 | if (!$folder) { |
||
95 | return false; |
||
96 | } |
||
97 | $tmp_props = mapi_getprops($folder, [PR_FOLDER_ID]); |
||
98 | if (empty($tmp_props[PR_FOLDER_ID])) { |
||
99 | return false; |
||
100 | } |
||
101 | $folder_id = IndexSqlite::get_gc_value((int) $tmp_props[PR_FOLDER_ID]); |
||
102 | $whereFolderids .= "c.folder_id in (" . $folder_id . ", "; |
||
103 | if ($recursive) { |
||
104 | $this->getWhereFolderids($folder, $whereFolderids); |
||
105 | } |
||
106 | $whereFolderids = substr($whereFolderids, 0, -2) . ") AND "; |
||
107 | } |
||
108 | catch (Exception $e) { |
||
109 | error_log(sprintf("Index: error getting folder information %s - %s", $this->username, $e)); |
||
110 | |||
111 | return false; |
||
112 | } |
||
113 | } |
||
114 | $sql_string = "SELECT c.message_id, c.entryid, c.folder_id, " . |
||
115 | "c.message_class, c.date, c.readflag, c.attach_indexed " . |
||
116 | "FROM msg_content c " . |
||
117 | "JOIN messages m ON c.message_id = m.rowid " . |
||
118 | "WHERE "; |
||
119 | if (!empty($whereFolderids)) { |
||
120 | $sql_string .= $whereFolderids; |
||
121 | } |
||
122 | $sql_string .= "messages MATCH '"; |
||
123 | $this->count = 0; |
||
124 | // Extract search_patterns into separate variables |
||
125 | [ |
||
126 | 'sender' => $sender, |
||
127 | 'sending' => $sending, |
||
128 | 'recipients' => $recipients, |
||
129 | 'subject' => $subject, |
||
130 | 'content' => $content, |
||
131 | 'attachments' => $attachments, |
||
132 | 'others' => $others, |
||
133 | 'message_classes' => $message_classes, |
||
134 | 'date_start' => $date_start, |
||
135 | 'date_end' => $date_end, |
||
136 | 'unread' => $unread, |
||
137 | 'has_attachments' => $has_attachments |
||
138 | ] = $search_patterns; |
||
139 | if (isset($sender) && $sender == $sending && $sending == $recipients && $recipients == $subject && |
||
140 | $subject == $content && $content == $attachments && $attachments == $others) { |
||
141 | $sql_string .= SQLite3::escapeString($this->quote_words($sender)) . "'"; |
||
142 | } |
||
143 | else { |
||
144 | $first = true; |
||
145 | foreach ($search_patterns as $key => $search_pattern) { |
||
146 | switch($key) { |
||
147 | case 'message_classes': |
||
148 | case 'date_start': |
||
149 | case 'date_end': |
||
150 | case 'unread': |
||
151 | case 'has_attachments': |
||
152 | break; |
||
153 | default: |
||
154 | if (!is_null($search_pattern)) { |
||
155 | if ($first === true) { |
||
156 | $first = false; |
||
157 | } |
||
158 | else { |
||
159 | $sql_string .= " OR "; |
||
160 | } |
||
161 | $sql_string .= $key . ':' . SQLite3::escapeString($this->quote_words($search_pattern)); |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | if ($first) { |
||
166 | return false; |
||
167 | } |
||
168 | $sql_string .= "'"; |
||
169 | } |
||
170 | $sql_string .= " ORDER BY c.date DESC LIMIT " . MAX_FTS_RESULT_ITEMS; |
||
171 | $results = $this->query($sql_string); |
||
172 | while (($row = $results->fetchArray(SQLITE3_ASSOC)) && !$this->result_full()) { |
||
173 | $this->try_insert_content( |
||
174 | $search_entryid, |
||
175 | $row, |
||
176 | $message_classes, |
||
177 | $date_start, |
||
178 | $date_end, |
||
179 | $unread, |
||
180 | $has_attachments |
||
181 | ); |
||
182 | } |
||
183 | |||
184 | return true; |
||
185 | } |
||
241 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.