diff --git a/Drupal_Apache_Solr_Service.php b/Drupal_Apache_Solr_Service.php
index 0dac1cf..a8ab116 100644
--- a/Drupal_Apache_Solr_Service.php
+++ b/Drupal_Apache_Solr_Service.php
@@ -719,7 +719,7 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  public function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+  public function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600) {
     $optimizeValue = $optimize ? 'true' : 'false';
     $flushValue = $waitFlush ? 'true' : 'false';
     $searcherValue = $waitSearcher ? 'true' : 'false';
@@ -803,7 +803,7 @@ class DrupalApacheSolrService implements DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  public function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600) {
+  public function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600) {
     $flushValue = $waitFlush ? 'true' : 'false';
     $searcherValue = $waitSearcher ? 'true' : 'false';
     $softCommit = $this->soft_commit ? 'true' : 'false';
diff --git a/apachesolr.admin.inc b/apachesolr.admin.inc
index c289638..a3f7dd0 100644
--- a/apachesolr.admin.inc
+++ b/apachesolr.admin.inc
@@ -7,8 +7,12 @@
 
 /**
  * Form to delete a search environment
- * @param $environment
- *   The environment to delete
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return mixed
  */
 function apachesolr_environment_delete_form($form, &$form_state, $environment) {
   $form['env_id'] = array(
@@ -31,6 +35,12 @@ function apachesolr_environment_delete_form($form, &$form_state, $environment) {
   );
 }
 
+/**
+ * Submit handler for the delete form
+ *
+ * @param array $form
+ * @param array $form_state
+ */
 function apachesolr_environment_delete_form_submit($form, &$form_state) {
   if (apachesolr_environment_delete($form_state['values']['env_id'])) {
     drupal_set_message(t('The search environment was deleted'));
@@ -47,6 +57,13 @@ function apachesolr_environment_edit_delete_submit($form, &$form_state) {
   drupal_get_destination();
 }
 
+/**
+ * Settings page for a specific environment (or default one if not provided)
+ *
+ * @param array|bool $environment
+ *
+ * @return array Render array for a settings page
+ */
 function apachesolr_environment_settings_page($environment = NULL) {
   if (empty($environment)) {
     $env_id = apachesolr_default_environment();
@@ -265,6 +282,10 @@ function apachesolr_check_facetapi() {
 
 /**
  * Form builder for general settings used as a menu callback.
+ * @param $form
+ * @param $form_state
+ *
+ * @return mixed
  */
 function apachesolr_settings($form, &$form_state) {
   $form = array();
diff --git a/apachesolr.index.inc b/apachesolr.index.inc
index b7479cf..2e20945 100644
--- a/apachesolr.index.inc
+++ b/apachesolr.index.inc
@@ -854,7 +854,7 @@ function apachesolr_index_node_solr_reindex($env_id, $bundle = NULL) {
 
     if ($bundle && !empty($indexable_bundles) && !in_array($bundle, $indexable_bundles)) {
       // The bundle specified is not in the indexable bundles list.
-      return;
+      return NULL;
     }
 
     $select = db_select('node', 'n');
diff --git a/apachesolr.install b/apachesolr.install
index 770d280..f5d5596 100644
--- a/apachesolr.install
+++ b/apachesolr.install
@@ -289,7 +289,7 @@ function apachesolr_uninstall() {
  */
 function apachesolr_update_7000() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   $schema['apachesolr_server'] = array(
@@ -368,7 +368,7 @@ function apachesolr_update_7000() {
  */
 function apachesolr_update_7001() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   if (db_field_exists('apachesolr_server', 'asid')) {
@@ -392,7 +392,7 @@ function apachesolr_update_7001() {
  */
 function apachesolr_update_7002() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   $schema['apachesolr_server_variable'] = array(
@@ -447,7 +447,7 @@ function apachesolr_update_7002() {
  */
 function apachesolr_update_7003() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   // Same as apachesolr_update_6006()
@@ -467,7 +467,7 @@ function apachesolr_update_7003() {
  */
 function apachesolr_update_7004() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   $failure = variable_get('apachesolr_failure', NULL);
@@ -489,7 +489,7 @@ function apachesolr_update_7004() {
  */
 function apachesolr_update_7005() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   if (db_field_exists('apachesolr_server', 'port')) {
@@ -522,7 +522,7 @@ function apachesolr_update_7005() {
  */
 function apachesolr_update_7006() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   variable_del('apachesolr_facetstyle');
@@ -536,7 +536,7 @@ function apachesolr_update_7006() {
  */
 function apachesolr_update_7007() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   db_drop_primary_key('apachesolr_server');
@@ -569,7 +569,7 @@ function apachesolr_update_7007() {
  */
 function apachesolr_update_7008() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   variable_del('apachesolr_facet_missing');
@@ -584,7 +584,7 @@ function apachesolr_update_7008() {
  */
 function apachesolr_update_7009() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   // Only run when facetapi is available and/or installed
@@ -620,7 +620,7 @@ function apachesolr_update_7009() {
  */
 function apachesolr_update_7010() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   db_drop_field('cache_apachesolr', 'headers');
@@ -632,7 +632,7 @@ function apachesolr_update_7010() {
  */
 function apachesolr_update_7011() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   $stored = variable_get('apachesolr_index_last', array());
@@ -649,7 +649,7 @@ function apachesolr_update_7011() {
  */
 function apachesolr_update_7012() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   // @see: drupal_load()
@@ -823,7 +823,7 @@ function apachesolr_update_7012() {
  */
 function apachesolr_update_7013() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   db_drop_primary_key('apachesolr_index_entities');
@@ -861,7 +861,7 @@ function apachesolr_update_7013() {
  */
 function apachesolr_update_7014() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   $types = array(
@@ -880,7 +880,7 @@ function apachesolr_update_7014() {
  */
 function apachesolr_update_7015() {
   if (variable_get('apachesolr_update_from_6303', FALSE)) {
-    return;
+    return NULL;
   }
 
   // Brand new installations since update_7013 have the wrong primary key.
diff --git a/apachesolr.interface.inc b/apachesolr.interface.inc
index a13fa8d..17bd8ed 100644
--- a/apachesolr.interface.inc
+++ b/apachesolr.interface.inc
@@ -448,7 +448,7 @@ interface DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600);
+  function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600);
 
   /**
    * Create a delete document based on document ID
@@ -497,7 +497,7 @@ interface DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600);
+  function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600);
 
   /**
    * Simple Search interface
diff --git a/apachesolr.module b/apachesolr.module
index 1202d1b..1e29e9f 100644
--- a/apachesolr.module
+++ b/apachesolr.module
@@ -907,7 +907,7 @@ function apachesolr_cron($env_id = NULL) {
   }
   // Indexes in read-only mode do not change the index, so will not update, delete, or optimize during cron.
   if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
-    return;
+    return NULL;
   }
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
 
@@ -933,7 +933,7 @@ function apachesolr_cron($env_id = NULL) {
     $last = variable_get('apachesolr_last_optimize', 0);
     $time = REQUEST_TIME;
     if ($optimize_interval && ($time - $last > $optimize_interval)) {
-      $solr->optimize(FALSE, FALSE);
+      $solr->optimize(false, FALSE);
       variable_set('apachesolr_last_optimize', $time);
       apachesolr_set_last_index_updated($env_id, $time);
     }
@@ -1524,24 +1524,24 @@ function apachesolr_static_response_cache($searcher, $response = NULL) {
 /**
  * Factory function for query objects.
  *
- * @param $name
+ * @param string $name
  *   The search name, used for finding the correct blocks and other config.
  *   Typically "apachesolr".
- * @param $params
+ * @param array $params
  *   Array of params , such as 'q', 'fq' to be applied.
- * @param $solrsort
+ * @param string $solrsort
  *   Visible string telling solr how to sort.
- * @param $base_path
+ * @param string $base_path
  *   The search base path (without the keywords) for this query.
- * @param $solr
- *   An instance of DrupalApacheSolrService.
+ * @param DrupalApacheSolrServiceInterface $solr
+ *   An instance of DrupalApacheSolrServiceInterface.
  *
- * @return
+ * @return DrupalSolrQueryInterface
  *   DrupalSolrQueryInterface object.
  *
  * @throws Exception
  */
-function apachesolr_drupal_query($name, array $params = array(), $solrsort = '', $base_path = '', $solr = NULL) {
+function apachesolr_drupal_query($name, array $params = array(), $solrsort = '', $base_path = '', DrupalApacheSolrServiceInterface $solr = NULL) {
   if (!interface_exists('DrupalSolrQueryInterface')) {
     require_once(dirname(__FILE__) . '/apachesolr.interface.inc');
   }
@@ -1563,10 +1563,10 @@ function apachesolr_drupal_query($name, array $params = array(), $solrsort = '',
  * Factory function for query objects.
  *
  * @param $operator
- *   Wether the subquery should be added to another query as OR or AND
+ *   Whether the subquery should be added to another query as OR or AND
  *
- * @return
- *   DrupalSolrQueryInterface object.
+ * @return DrupalSolrQueryInterface|false
+ *   Subquery or error.
  *
  * @throws Exception
  */
@@ -1583,11 +1583,20 @@ function apachesolr_drupal_subquery($operator = 'OR') {
   if (!class_exists($class_info['class']) && isset($class_info['file']) && isset($class_info['module'])) {
     module_load_include('php', $class_info['module'], $class_info['file']);
   }
-  return new $class($operator);
+  $query = new $class($operator);
+  return $query;
 }
 
 /**
  * Static getter/setter for the current query. Only set once per page.
+ *
+ * @param $env_id
+ *   Environment from which to save or get the current query
+ * @param DrupalSolrQueryInterface $query
+ *   $query object to save in the static
+ *
+ * @return DrupalSolrQueryInterface|null
+ *   return the $query object if it is available in the drupal_static or null otherwise
  */
 function apachesolr_current_query($env_id, DrupalSolrQueryInterface $query = NULL) {
   $saved_query = &drupal_static(__FUNCTION__, NULL);
@@ -1883,7 +1892,7 @@ function apachesolr_entity_update($entity, $type) {
     // Delete the entity from our index if the status callback returns FALSE
     if (!$status) {
       apachesolr_entity_delete($entity, $type);
-      return;
+      return NULL;
     }
 
     $indexer_table = apachesolr_get_indexer_table($type);
@@ -1973,7 +1982,7 @@ function apachesolr_entity_fields($entity_type = 'node') {
           'facet missing allowed' => FALSE,
           'facet mincount allowed' => FALSE,
           // Field API allows any field to be multi-valued.
-          'multiple' => TRUE,
+          'multiple' => FALSE,
         );
       if ($key !== 'per-field') {
         $mappings[$key] += $defaults;
@@ -2616,7 +2625,7 @@ function theme_apachesolr_settings_title($vars) {
 function apachesolr_environment_load_subrecords(&$environments) {
   if (empty($environments)) {
     // Nothing to do.
-    return;
+    return NULL;
   }
 
   $all_index_bundles = db_select('apachesolr_index_bundles', 'ib')
diff --git a/apachesolr_access/apachesolr_access.module b/apachesolr_access/apachesolr_access.module
index bac5a28..2ee8e6c 100644
--- a/apachesolr_access/apachesolr_access.module
+++ b/apachesolr_access/apachesolr_access.module
@@ -2,8 +2,18 @@
 
 /**
  * Implements hook_apachesolr_index_document_build_node()
+ *
+ * Add node access grants of generic view grants if node access is not used.
+ *
+ * @param $document
+ *   The document to add our node access information to
+ * @param $node
+ *   The node which is used to built the document from
+ * @param $env_id
+ *   The environment for which we are building the document. This parameter does not have any effect in
+ *   this code so it can be ignored
  */
-function apachesolr_access_apachesolr_index_document_build_node($document, $node, $env_id) {
+function apachesolr_access_apachesolr_index_document_build_node(ApacheSolrDocument $document, $node, $env_id) {
   $account = &drupal_static(__FUNCTION__);
 
   if (!isset($account)) {
@@ -17,23 +27,27 @@ function apachesolr_access_apachesolr_index_document_build_node($document, $node
     foreach ($result as $grant) {
       $grant_realm = apachesolr_access_clean_realm_name($grant->realm);
       $key = 'access_node_' . apachesolr_site_hash() . '_' . $grant_realm;
-      $document->setMultiValue($key, $grant->gid);
+      $document->addField($key, $grant->gid);
     }
   }
   else {
     // Add the generic view grant if we are not using
     // node access or the node is viewable by anonymous users.
     // We assume we'll never have an entity with the name '__all'.
-    $document->setMultiValue('access__all', 0);
+    $document->addField('access__all', 0);
   }
 }
 
 /**
  * Creates a Solr query for a given user
  *
- * @param $account an account to get grants for and build a solr query
+ * @param $account
+ *   an account to get grants for and build a solr query
  *
  * @throws Exception
+ *
+ * @return SolrFilterSubQuery
+ *   Instance of SolrFilterSubQuery
  */
 function apachesolr_access_build_subquery($account) {
   if (!user_access('access content', $account)) {
@@ -61,6 +75,11 @@ function apachesolr_access_build_subquery($account) {
 
 /**
  * Implements hook_apachesolr_query_alter().
+ *
+ * Alter the query to include the access subquery
+ *
+ * @param DrupalSolrQueryInterface $query
+ *
  */
 function apachesolr_access_apachesolr_query_alter(DrupalSolrQueryInterface $query) {
   global $user;
@@ -76,7 +95,10 @@ function apachesolr_access_apachesolr_query_alter(DrupalSolrQueryInterface $quer
 
 /**
  * Implements hook_node_insert().
- * hook_node*() is called before hook_node_access_records() in node_save().
+ *
+ * hook_node_ACTION() is called before hook_node_access_records() in node_save().
+ *
+ * @param object $node
  */
 function apachesolr_access_node_insert($node) {
   $node->apachesolr_access_node_ignore = 1;
@@ -84,6 +106,10 @@ function apachesolr_access_node_insert($node) {
 
 /**
  * Implements hook_node_update().
+ *
+ * hook_node_ACTION() is called before hook_node_access_records() in node_save().
+ *
+ * @param object $node
  */
 function apachesolr_access_node_update($node) {
   $node->apachesolr_access_node_ignore = 1;
@@ -94,6 +120,8 @@ function apachesolr_access_node_update($node) {
  *
  * Listen to this hook to find out when a node needs to be re-indexed
  * for its node access grants.
+ *
+ * @param object $node
  */
 function apachesolr_access_node_access_records($node) {
   // node_access_needs_rebuild() will usually be TRUE during a
@@ -106,6 +134,11 @@ function apachesolr_access_node_access_records($node) {
 
 /**
  * Implements hook_form_alter().
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param string $form_id
+ *
  */
 function apachesolr_access_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'node_configure_rebuild_confirm') {
@@ -118,6 +151,10 @@ function apachesolr_access_form_alter(&$form, $form_state, $form_id) {
  *
  * This is unfortunate because not every node is going to be affected, but
  * there is little we can do.
+ *
+ * @param $form
+ * @param $form_state
+ *
  */
 function apachesolr_access_rebuild_nodeaccess(&$form, $form_state) {
   drupal_set_message(t('Solr search index will be rebuilt.'));
@@ -125,12 +162,24 @@ function apachesolr_access_rebuild_nodeaccess(&$form, $form_state) {
   apachesolr_clear_last_index_position();
 }
 
+/**
+ * Implements hook_enable().
+ *
+ * On enabling the module, tell the user to reindex
+ */
 function apachesolr_access_enable() {
   drupal_set_message(t('Your content <a href="@url">must be re-indexed</a> before Apache Solr Access will be functional on searches.', array('@url' => url('admin/config/search/apachesolr/index'))), 'warning');
 }
 
 /**
  * Helper function - return a safe (PHP identifier) realm name.
+ *
+ * @todo See if we can replace this with a native php function
+ *
+ * @param string $realm
+ *
+ * @return string
+ *   Clean string without bad characters
  */
 function apachesolr_access_clean_realm_name($realm) {
   return preg_replace('/[^a-zA-Z0-9_\x7f-\xff]/', '_', $realm);
diff --git a/apachesolr_access/tests/apachesolr_access.test b/apachesolr_access/tests/apachesolr_access.test
index 99c6765..9a0f3e1 100644
--- a/apachesolr_access/tests/apachesolr_access.test
+++ b/apachesolr_access/tests/apachesolr_access.test
@@ -5,6 +5,13 @@
  *   apachesolr_access.
  */
 class DrupalApacheSolrNodeAccess extends DrupalWebTestCase {
+
+  /**
+   * Gets Information about the DrupalApacheSolrNodeAccess test
+   *
+   * @return array
+   *   Information such as name, description and group it belongs to
+   */
   public static function getInfo() {
     return array(
       'name' => 'Node Access',
@@ -13,10 +20,13 @@ class DrupalApacheSolrNodeAccess extends DrupalWebTestCase {
     );
   }
 
+  /**
+   * Defines what is required to start the DrupalApacheSolrNodeAccess test.
+   */
   function setUp() {
     parent::setUp('node_access_test', 'apachesolr', 'apachesolr_search', 'apachesolr_access');
 
-     // Create a basic user, which is subject to moderation.
+    // Create a basic user, which is subject to moderation.
     $permissions = array(
       'access content',
       'create page content',
@@ -36,6 +46,9 @@ class DrupalApacheSolrNodeAccess extends DrupalWebTestCase {
     $this->admin_user = $this->drupalCreateUser($permissions);
   }
 
+  /**
+   * Tests indexing and check if it adds the correct grants for those specific users
+   */
   function testIndexing() {
     $basic_user = $this->basic_user;
     // Login as basic user to perform initial content creation.
@@ -117,7 +130,7 @@ class DrupalApacheSolrNodeAccess extends DrupalWebTestCase {
     $settings = apachesolr_search_mlt_block_defaults();
     // Dummy value
     $id = apachesolr_document_id($author_restricted_node->nid);
-    drupal_save_session(FALSE);
+    drupal_save_session(false);
     $GLOBALS['user'] = $basic_user;
     $response = apachesolr_search_mlt_suggestions($settings, $id, $solr);
     $search = $solr->getLastSearch();
diff --git a/apachesolr_search.module b/apachesolr_search.module
index 4132abe..f75888a 100644
--- a/apachesolr_search.module
+++ b/apachesolr_search.module
@@ -15,7 +15,7 @@
 function apachesolr_search_init() {
   // Useless without facetapi
   if (!module_exists('facetapi')) {
-    return;
+    return NULL;
   }
 
   // Using a simple query we will figure out if we have to execute this snippet
@@ -25,7 +25,7 @@ function apachesolr_search_init() {
     WHERE name = 'apachesolr_search_show_facets'";
   $count = db_query($query)->fetchField();
   if ($count == 0) {
-    return;
+    return NULL;
   }
 
   // Load the default search page, we only support facets to link to this
@@ -34,7 +34,7 @@ function apachesolr_search_init() {
   $search_page = apachesolr_search_page_load($search_page_id);
   // Do not continue if our search page is not valid
   if (empty($search_page)) {
-    return;
+    return NULL;
   }
 
   $show_facets = apachesolr_environment_variable_get($search_page['env_id'], 'apachesolr_search_show_facets', 0);
@@ -277,7 +277,7 @@ function apachesolr_search_get_taxonomy_term_title($search_page_id = NULL, $valu
      $page_title = str_replace('%value', '!value', $search_page['page_title']);
      $term = taxonomy_term_load($value);
      if (!$term) {
-       return;
+       return NULL;
      }
      $title = $term->name;
    }
@@ -299,7 +299,7 @@ function apachesolr_search_get_user_title($search_page_id = NULL, $value = NULL)
     $page_title = str_replace('%value', '!value', $search_page['page_title']);
     $user = user_load($value);
     if (!$user) {
-       return;
+       return NULL;
      }
     $title = $user->name;
   }
@@ -440,7 +440,7 @@ function apachesolr_search_block_view($delta = '') {
         
         // If there are less than two results, do not return the sort block
         if (empty($response) || ($response->response->numFound < 2)) {
-          return;
+          return NULL;
         }
 
         // Check if we have to return a cached version of this block
@@ -670,7 +670,7 @@ function apachesolr_search_mlt_suggestions($settings, $id, $solr = NULL) {
     // This hook allows modules to modify the query object.
     drupal_alter('apachesolr_query', $query);
     if ($query->abort_search) {
-      return;
+      return NULL;
     }
 
     $response = $query->search();
@@ -1073,7 +1073,7 @@ function apachesolr_search_run($name, array $params = array(), $solrsort = '', $
     $query->addParam('fl', 'teaser');
   }
 
-  list($final_query, $response) = apachesolr_do_query($query, $page);
+  list($final_query, $response) = apachesolr_do_query($query);
   $env_id = $query->solr('getId');
   apachesolr_has_searched($env_id, TRUE);
   $process_response_callback = apachesolr_environment_variable_get($env_id, 'process_response_callback', 'apachesolr_search_process_response');
@@ -1462,7 +1462,7 @@ function apachesolr_search_preprocess_search_results(&$variables) {
     }
     if (empty($variables['response'])) {
       $variables['description'] = '';
-      return;
+      return NULL;
     }
     $total = $variables['response']->response->numFound;
     $params = $variables['query']->getParams();
diff --git a/drush/apachesolr.drush.inc b/drush/apachesolr.drush.inc
index 0c580bd..368d0ae 100644
--- a/drush/apachesolr.drush.inc
+++ b/drush/apachesolr.drush.inc
@@ -175,16 +175,23 @@ function apachesolr_drush_command() {
 function apachesolr_drush_help($section) {
   switch ($section) {
     case 'drush:solr-delete-index':
-      return dt("Used without parameters, this command deletes the entire Solr index. Used with parameters for content type, it deletes just the content types that are specified. After the index has been deleted, all content will be indexed again on future cron runs.");
+      return dt("Used without parameters, this command deletes the entire Solr index.
+        Used with parameters for content type, it deletes just the content types that are specified.
+        After the index has been deleted, all content will be indexed again on future cron runs.");
     case 'drush:solr-mark-all':
-      return dt("Used without parameters, this command marks all of the content in the Solr index for reindexing. Used with paramters for content type, it marks just the content types that are specified. Reindexing is different than deleting as the content is still searchable while it is in queue to be reindexed. Reindexing is done on future cron runs.");
+      return dt("Used without parameters, this command marks all of the content in the Solr index for
+        reindexing. Used with parameters for content type, it marks just the content types that are specified.
+        Reindexing is different than deleting as the content is still searchable while it is in queue to be reindexed.
+        Reindexing is done on future cron runs.");
     case 'drush:solr-index':
-      return dt("Reindexes content marked for (re)indexing. If you want to reindex all content or content of a specific type, use solr-reindex first to mark that content.");
+      return dt("Reindexes content marked for (re)indexing. If you want to reindex all content or content
+         of a specific type, use solr-reindex first to mark that content.");
     case 'drush:solr-search':
-      return dt('Executes a search against the site\'s Apache Solr search index and returns the restults.');
+      return dt('Executes a search against the site\'s Apache Solr search index and returns the results.');
     case 'error:APACHESOLR_ENV_ID_ERROR':
       return dt('Not a valid environment ID.');
   }
+  return '';
 }
 
 /**
@@ -221,6 +228,9 @@ function apachesolr_drush_solr_delete_index() {
   drush_print(t('Deleted the Solr index'));
 }
 
+/**
+ * Mark all of a specific environment id for reindexing
+ */
 function apachesolr_drush_solr_mark_for_reindex() {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
   $args = func_get_args();
@@ -236,6 +246,9 @@ function apachesolr_drush_solr_mark_for_reindex() {
   drush_print(t('Marked content for reindexing'));
 }
 
+/**
+ * Index all the items in the queue using a batch command
+ */
 function apachesolr_drush_solr_index() {
   module_load_include('inc', 'apachesolr', 'apachesolr.admin');
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
@@ -244,6 +257,12 @@ function apachesolr_drush_solr_index() {
   drush_backend_batch_process();
 }
 
+/**
+ * Get the last indexed document
+ *
+ * @param string $env_id
+ * @param string $entity_type
+ */
 function apachesolr_drush_solr_get_last_indexed($env_id = NULL, $entity_type = 'node') {
   if (NULL === $env_id) {
     $env_id = apachesolr_default_environment();
@@ -262,6 +281,9 @@ function apachesolr_drush_solr_get_next_indexed($env_id = NULL, $entity_type = '
   drush_print($output);
 }
 
+/**
+ * Search the solr index using Drush
+ */
 function apachesolr_drush_solr_search() {
   $args = func_get_args();
   $keys = implode(' ', $args);
@@ -277,6 +299,9 @@ function apachesolr_drush_solr_search() {
   }
 }
 
+/**
+ * Get all the environments (using option all) or get the default environment id
+ */
 function apachesolr_drush_solr_get_env_id() {
   $all = drush_get_option('all');
 
@@ -291,6 +316,14 @@ function apachesolr_drush_solr_get_env_id() {
   }
 }
 
+/**
+ * Get the environment name based on the environment ID
+ *
+ * @print The environment name
+ *
+ * @return mixed APACHESOLR_ENV_ID_ERROR
+ *   Only return error if the environment can't be found
+ */
 function apachesolr_drush_solr_get_env_name() {
   $env_id = drush_get_option('id', apachesolr_default_environment());
   try {
@@ -302,6 +335,14 @@ function apachesolr_drush_solr_get_env_name() {
   drush_print($environment['name']);
 }
 
+/**
+ * Get the environment url based on the environment ID
+ *
+ * @print The environment url
+ *
+ * @return mixed APACHESOLR_ENV_ID_ERROR
+ *   Only return error if the environment can't be found
+ */
 function apachesolr_drush_solr_get_env_url() {
   $env_id = drush_get_option('id', apachesolr_default_environment());
   try {
@@ -313,6 +354,14 @@ function apachesolr_drush_solr_get_env_url() {
   drush_print($environment['url']);
 }
 
+/**
+ * Set the environment url based on the environment ID
+ *
+ * @param $url
+ *
+ * @return mixed APACHESOLR_ENV_ID_ERROR
+ *   Only return error if the environment can't be found
+ */
 function apachesolr_drush_solr_set_env_url($url) {
   $env_id = drush_get_option('id', apachesolr_default_environment());
   try {
@@ -325,11 +374,15 @@ function apachesolr_drush_solr_set_env_url($url) {
   apachesolr_environment_save($environment);
 }
 
-/*** variable code - much of it copied from dush core **/
-
 /**
  * Command callback.
+ *
  * List your site's variables.
+ * much of it copied from drush core
+ *
+ * @param string $arg_name
+ *
+ * @return array|mixed Could be the variable or a drush error
  */
 function drush_apachesolr_solr_variable_get($arg_name = NULL) {
   $output = NULL;
@@ -360,6 +413,11 @@ function drush_apachesolr_solr_variable_get($arg_name = NULL) {
 /**
  * Command callback.
  * Set a variable.
+ *
+ * @param string $arg_name
+ * @param mixed $value
+ *
+ * @return mixed
  */
 function drush_apachesolr_solr_variable_set($arg_name, $value) {
   $args = func_get_args();
@@ -422,6 +480,15 @@ function drush_apachesolr_solr_variable_set($arg_name, $value) {
   }
 }
 
+/**
+ *
+ * Format a specific variable
+ *
+ * @param $value
+ * @param $format
+ *
+ * @return bool|int|string
+ */
 function _apachesolr_drush_variable_format($value, $format) {
   if ($format == 'auto') {
     if (is_numeric($value)) {
@@ -461,6 +528,9 @@ function _apachesolr_drush_variable_format($value, $format) {
 /**
  * Command callback.
  * Delete a variable.
+ * @param $arg_name
+ *
+ * @return string
  */
 function drush_apachesolr_solr_variable_delete($arg_name) {
 
@@ -503,6 +573,9 @@ function drush_apachesolr_solr_variable_delete($arg_name) {
 /**
  * Load an environment from an id and validate the result.
  *
+ * @param string $env_id
+ *
+ * @return array $environment
  * @throws Exception
  */
 function _apachesolr_drush_environment_load_and_validate($env_id) {
@@ -517,7 +590,14 @@ function _apachesolr_drush_environment_load_and_validate($env_id) {
 /**
  * Search for similar variable names.
  *
+ * @param string $env_id
+ * @param string $arg
+ * @param bool|string $starts_with
+ *
  * @throws Exception
+ *
+ * @return array $variable
+ *   Only return it if found
  */
 function _apachesolr_drush_variable_like($env_id, $arg = NULL, $starts_with = FALSE) {
   $found = array();
diff --git a/plugins/facetapi/adapter.inc b/plugins/facetapi/adapter.inc
index cee20b5..87f4e3a 100644
--- a/plugins/facetapi/adapter.inc
+++ b/plugins/facetapi/adapter.inc
@@ -9,17 +9,19 @@
  * Facet API adapter for the Apache Solr Search Integration module.
  */
 class ApacheSolrFacetapiAdapter extends FacetapiAdapter {
+
   /**
    * Returns the path to the admin settings for a given realm.
    *
-   * @param $realm_name
+   * @param string $realm_name
    *   The name of the realm.
    *
-   * @return
+   * @return string
    *   The path to the admin settings.
    */
   public function getPath($realm_name) {
     $path = 'admin/config/search/apachesolr/settings';
+    // $adapter will be an instance of class FacetapiAdapter
     if ($adapter = menu_get_object('facetapi_adapter', 4)) {
       // Get the environment ID from the machine name of the searcher.
       $env_id = ltrim(strstr($adapter->getSearcher(), '@'), '@');
@@ -60,6 +62,14 @@ class ApacheSolrFacetapiAdapter extends FacetapiAdapter {
     return $this_has_searched;
   }
 
+  /**
+   * Suppress output of the realm
+   *
+   * @param string $realm_name
+   *
+   * @return bool $flag
+   *   Returns if it was suppressed or not
+   */
   public function suppressOutput($realm_name) {
     $flag = FALSE;
     if ($realm_name == 'block') {
@@ -71,6 +81,8 @@ class ApacheSolrFacetapiAdapter extends FacetapiAdapter {
 
   /**
    * Returns the search keys.
+   *
+   * @return string
    */
   public function getSearchKeys() {
     if (NULL === $this->keys) {
@@ -82,6 +94,7 @@ class ApacheSolrFacetapiAdapter extends FacetapiAdapter {
     else {
       return $this->keys;
     }
+    return FALSE;
   }
 
   /**
@@ -114,16 +127,23 @@ class ApacheSolrFacetapiAdapter extends FacetapiAdapter {
 
   /**
    * Returns the number of total results found for the current search.
+   *
+   * @return bool|int
+   *   Number of results or false if no search response was found
    */
   public function getResultCount() {
     $response = apachesolr_static_response_cache($this->getSearcher());
     if ($response) {
       return $response->response->numFound;
     }
+    return FALSE;
   }
 
   /**
    * Allows for backend specific overrides to the settings form.
+   *
+   * @param array $form
+   * @param array $form_state
    */
   public function settingsForm(&$form, &$form_state) {
     $form['#validate'][] = 'apachesolr_facet_form_validate';
diff --git a/plugins/facetapi/query_type_date.inc b/plugins/facetapi/query_type_date.inc
index c1b3946..0b72e4a 100644
--- a/plugins/facetapi/query_type_date.inc
+++ b/plugins/facetapi/query_type_date.inc
@@ -30,7 +30,7 @@ class ApacheSolrFacetapiDate extends FacetapiQueryTypeDate implements FacetapiQu
     // Gets the data range in formats that Solr understands.
     $date_range = $this->getDateRange($query);
     if (empty($date_range)) {
-      return;
+      return NULL;
     }
     list($start, $end, $gap) = $date_range;
     $query->addParam('facet.date', $this->facet['field']);
@@ -53,22 +53,23 @@ class ApacheSolrFacetapiDate extends FacetapiQueryTypeDate implements FacetapiQu
   /**
    * Gets the range of dates we are using.
    *
-   * @param $query
+   * @param DrupalSolrQueryInterface $query
    *   A SolrBaseQuery object.
    *
-   * @return
-   *   An array containing the gap and range information.
+   * @return bool|array
+   *   An array containing the gap and range information or false if not present
    */
   function getDateRange(DrupalSolrQueryInterface $query) {
     $return = NULL;
+    $gap = NULL;
 
     // Attempts to get next gap from passed date filters.
-    foreach ($this->adapter->getActiveItems($this->facet) as $value => $item) {
+    foreach ($this->adapter->getActiveItems($this->facet) as $item) {
       if ($gap = facetapi_get_date_gap($item['start'], $item['end'])) {
         $next_gap = facetapi_get_next_date_gap($gap, FACETAPI_DATE_SECOND);
         if ($next_gap == $gap) {
           $next_gap = NULL;
-          return;
+          return NULL;
         }
         $return = array(
           "{$item['start']}/$next_gap",
@@ -91,7 +92,7 @@ class ApacheSolrFacetapiDate extends FacetapiQueryTypeDate implements FacetapiQu
       }
 
       // Gets the default gap.
-      $gap = FACETAPI_DATE_YEAR;
+      //$gap = FACETAPI_DATE_YEAR;
       if ($minimum && $maximum) {
         $gap = facetapi_get_timestamp_gap($minimum, $maximum);
         $minimum = facetapi_isodate($minimum, $gap);
@@ -150,8 +151,8 @@ class ApacheSolrFacetapiDate extends FacetapiQueryTypeDate implements FacetapiQu
     else {
       $raw_data = array();
     }
-    $end = (!empty($raw_data['end'])) ? $raw_data['end'] : '';
-    $start = (!empty($raw_data['start'])) ? $raw_data['start'] : '';
+    //$end = (!empty($raw_data['end'])) ? $raw_data['end'] : '';
+    //$start = (!empty($raw_data['start'])) ? $raw_data['start'] : '';
     $gap = (!empty($raw_data['gap'])) ? $raw_data['gap'] : '';
 
     // We cannot list anything below a minute (range of 00 seconds till 59
@@ -163,7 +164,6 @@ class ApacheSolrFacetapiDate extends FacetapiQueryTypeDate implements FacetapiQu
 
       // Treat each date facet as a range start, and use the next date facet
       // as range end.  Use 'end' for the final end.
-      $range_end = array();
       $previous = NULL;
 
       // Builds facet counts object used by the server.
diff --git a/tests/Dummy_Solr.php b/tests/Dummy_Solr.php
index 84d3ca1..dac7dd8 100644
--- a/tests/Dummy_Solr.php
+++ b/tests/Dummy_Solr.php
@@ -379,7 +379,7 @@ class DummySolr implements DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  function commit($optimize = true, $waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
+  function commit($optimize = TRUE, $waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600, $softCommit = FALSE) {
   }
 
   /**
@@ -432,7 +432,7 @@ class DummySolr implements DrupalApacheSolrServiceInterface {
    *
    * @throws Exception If an error occurs during the service call
    */
-  function optimize($waitFlush = true, $waitSearcher = true, $timeout = 3600, $softCommit = false) {
+  function optimize($waitFlush = TRUE, $waitSearcher = TRUE, $timeout = 3600, $softCommit = FALSE) {
   }
 }
 
