Browse Source

Coding Standards: Final cleanup for tripal_search; added @coder-ignore for errors to be ignored

Lacey Sanderson 12 years ago
parent
commit
73c9af1773
2 changed files with 21 additions and 0 deletions
  1. 8 0
      tripal_search/tripal_search.coder_ignores.txt
  2. 13 0
      tripal_search/tripal_search.module

+ 8 - 0
tripal_search/tripal_search.coder_ignores.txt

@@ -0,0 +1,8 @@
+; The file should be formatted this way :
+; file:line:warning-type
+; where warning-type is one of security, style, sql, i18n, comment, etc.
+
+; Can't use db placeholders in this case since the variable contains the SQL describing
+; a join and this would be sanitized if that was added through a placeholder
+tripal_search.module:126:sql
+tripal_search.module:136:sql

+ 13 - 0
tripal_search/tripal_search.module

@@ -122,6 +122,7 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   }
 
   // Calculate maximum keyword relevance, to normalize it.
+  // @coder-ignore: can't use placeholders since variable defines a join
   $select = "SELECT SUM(i.score * t.count) AS score FROM {search_index} i " . $join . " WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d ORDER BY score DESC";
   $arguments = array_merge($arguments1, array($query[4]));
   $normalize = db_result(db_query_range($select, $arguments, 0, 1));
@@ -131,6 +132,7 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   $columns2 = str_replace('i.relevance', '('. (1.0 / $normalize) .' * SUM(i.score * t.count))', $columns2);
 
   // Build query to retrieve results.
+  // @coder-ignore: can't use placeholders since variable defines a join
   $select = "SELECT i.type, i.sid, $columns2 FROM {search_index} i " . $join . " " . $join2 . " WHERE $conditions GROUP BY i.type, i.sid HAVING COUNT(*) >= %d";
   $count_select =  "SELECT COUNT(*) FROM ($select) n1";
   $arguments = array_merge($arguments2, $arguments1, array($query[4]));
@@ -144,3 +146,14 @@ function tripal_do_search($keywords, $type, $join1 = '', $where1 = '1 = 1', $arg
   }
   return $results;
 }
+
+/**
+ * Implements hook_coder_ignore().
+ * Defines the path to the file (tripal_search.coder_ignores.txt) where ignore rules for coder are stored
+ */
+function tripal_search_coder_ignore() {
+  return array(
+    'path' => drupal_get_path('module', 'tripal_search'),
+    'line prefix' => drupal_get_path('module', 'tripal_search'),
+  );
+}