diff --git a/Apache_Solr_Document.php b/Apache_Solr_Document.php
index 8bdcfb4..3d1b924 100644
--- a/Apache_Solr_Document.php
+++ b/Apache_Solr_Document.php
@@ -59,20 +59,17 @@
 /**
  * Holds Key / Value pairs that represent a Solr Document along with any associated boost
  * values. Field values can be accessed by direct dereferencing such as:
- * <code>
- * ...
+ *
+ * @code
  * $document->title = 'Something';
  * echo $document->title;
- * ...
- * </code>
  *
  * Additionally, the field values can be iterated with foreach
  *
- * <code>
- * foreach ($document as $fieldName => $fieldValue)
- * {
- * ...
- * }
+ * @code
+ *   foreach ($document as $fieldName => $fieldValue) {
+ *   ...
+ *   }
  * </code>
  */
 class ApacheSolrDocument implements IteratorAggregate {
@@ -111,7 +108,8 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Get current document boost
    *
-   * @return mixed will be false for default, or else a float
+   * @return mixed
+   *   will be false for default, or else a float
    */
   public function getBoost() {
     return $this->_documentBoost;
@@ -120,7 +118,8 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Set document boost factor
    *
-   * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
+   * @param mixed $boost
+   *   Use false for default boost, else cast to float that should be > 0 or will be treated as false
    */
   public function setBoost($boost) {
     $boost = (float) $boost;
@@ -142,19 +141,17 @@ class ApacheSolrDocument implements IteratorAggregate {
    * field boost value will be the product of all specified boosts
    * on field values - this is similar to SolrJ's functionality.
    *
-   * <code>
-   * $doc = new ApacheSolrDocument();
-   *
-   * $doc->addField('foo', 'bar', 2.0);
-   * $doc->addField('foo', 'baz', 3.0);
-   *
-   * // resultant field boost will be 6!
-   * echo $doc->getFieldBoost('foo');
-   * </code>
+   * @code
+   *   $doc = new ApacheSolrDocument();
+   *   $doc->addField('foo', 'bar', 2.0);
+   *   $doc->addField('foo', 'baz', 3.0);
+   *   // resultant field boost will be 6!
+   *   echo $doc->getFieldBoost('foo');
    *
    * @param string $key
    * @param mixed $value
-   * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
+   * @param mixed $boost
+   *   Use false for default boost, else cast to float that should be > 0 or will be treated as false
    */
   public function addField($key, $value, $boost = FALSE) {
     if (!isset($this->_fields[$key])) {
@@ -184,7 +181,8 @@ class ApacheSolrDocument implements IteratorAggregate {
    *
    * @param string $key
    * @param string $value
-   * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
+   * @param mixed $boost
+   *   Use false for default boost, else cast to float that should be > 0 or will be treated as false
    *
    * @deprecated Use addField(...) instead
    */
@@ -217,7 +215,8 @@ class ApacheSolrDocument implements IteratorAggregate {
    *
    * @param string $key
    * @param mixed $value
-   * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
+   * @param mixed $boost
+   *   Use false for default boost, else cast to float that should be > 0 or will be treated as false
    */
   public function setField($key, $value, $boost = FALSE) {
     $this->_fields[$key] = $value;
@@ -228,7 +227,8 @@ class ApacheSolrDocument implements IteratorAggregate {
    * Get the currently set field boost for a document field
    *
    * @param string $key
-   * @return float currently set field boost, false if one is not set
+   * @return float
+   *   currently set field boost, false if one is not set
    */
   public function getFieldBoost($key) {
     return isset($this->_fieldBoosts[$key]) ? $this->_fieldBoosts[$key] : FALSE;
@@ -237,8 +237,10 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Set the field boost for a document field
    *
-   * @param string $key field name for the boost
-   * @param mixed $boost Use false for default boost, else cast to float that should be > 0 or will be treated as false
+   * @param string $key
+   *   field name for the boost
+   * @param mixed $boost
+   *   Use false for default boost, else cast to float that should be > 0 or will be treated as false
    */
   public function setFieldBoost($key, $boost) {
     $boost = (float) $boost;
@@ -281,12 +283,11 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * IteratorAggregate implementation function. Allows usage:
    *
-   * <code>
-   * foreach ($document as $key => $value)
-   * {
-   *   ...
-   * }
-   * </code>
+   * @code
+   *   foreach ($document as $key => $value) {
+   *     ...
+   *   }
+   *
    */
   public function getIterator() {
     $arrayObject = new ArrayObject($this->_fields);
@@ -319,12 +320,12 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Magic isset for fields values.  Do not call directly. Allows usage:
    *
-   * <code>
-   * isset($document->some_field);
-   * </code>
+   * @code
+   *   isset($document->some_field);
    *
    * @param string $key
    * @return boolean
+   *   Whether the given key is set in the document
    */
   public function __isset($key) {
     return isset($this->_fields[$key]);
@@ -333,9 +334,8 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Magic unset for field values. Do not call directly. Allows usage:
    *
-   * <code>
-   * unset($document->some_field);
-   * </code>
+   * @code
+   *   unset($document->some_field);
    *
    * @param string $key
    */
@@ -347,7 +347,10 @@ class ApacheSolrDocument implements IteratorAggregate {
   /**
    * Create an XML fragment from a ApacheSolrDocument instance appropriate for use inside a Solr add call
    *
+   * @param ApacheSolrDocument $document
+   *
    * @return string
+   *   an xml formatted string from the given document
    */
   public static function documentToXml(ApacheSolrDocument $document) {
     $xml = '<doc';
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 c280cae..a9bd31b 100644
--- a/apachesolr.admin.inc
+++ b/apachesolr.admin.inc
@@ -7,10 +7,14 @@
 
 /**
  * Form to delete a search environment
- * @param $environment
- *   The environment to delete
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return array output of confirm_form()
  */
-function apachesolr_environment_delete_form($form, &$form_state, $environment) {
+function apachesolr_environment_delete_form(array $form, array &$form_state, array $environment) {
   $form['env_id'] = array(
     '#type' => 'value',
     '#value' => $environment['env_id'],
@@ -31,7 +35,13 @@ function apachesolr_environment_delete_form($form, &$form_state, $environment) {
   );
 }
 
-function apachesolr_environment_delete_form_submit($form, &$form_state) {
+/**
+ * Submit handler for the delete form
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_delete_form_submit(array $form, array &$form_state) {
   if (apachesolr_environment_delete($form_state['values']['env_id'])) {
     drupal_set_message(t('The search environment was deleted'));
   }
@@ -47,7 +57,14 @@ function apachesolr_environment_edit_delete_submit($form, &$form_state) {
   drupal_get_destination();
 }
 
-function apachesolr_environment_settings_page($environment = NULL) {
+/**
+ * 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(array $environment = array()) {
   if (empty($environment)) {
     $env_id = apachesolr_default_environment();
     $environment = apachesolr_environment_load($env_id);
@@ -66,7 +83,16 @@ function apachesolr_environment_settings_page($environment = NULL) {
   return $output;
 }
 
-function apachesolr_environment_clone_form($form, &$form_state, $environment) {
+/**
+ * Form to clone a certain environment
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return array output of confirm_form()
+ */
+function apachesolr_environment_clone_form(array $form, array &$form_state, array $environment) {
   $form['env_id'] = array(
     '#type' => 'value',
     '#value' => $environment['env_id'],
@@ -81,21 +107,33 @@ function apachesolr_environment_clone_form($form, &$form_state, $environment) {
   );
 }
 
-function apachesolr_environment_clone_form_submit($form, &$form_state) {
+/**
+ * Submit handler for the clone form
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_clone_form_submit(array $form, array &$form_state) {
   if (apachesolr_environment_clone($form_state['values']['env_id'])) {
     drupal_set_message(t('The search environment was cloned'));
   }
   $form_state['redirect'] = 'admin/config/search/apachesolr/settings';
 }
 
-function apachesolr_environment_clone_submit($form, &$form_state) {
+/**
+ * Submit handler for the confirmation page of cloning an environment
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_clone_submit(array $form, array &$form_state) {
   $form_state['redirect'] = 'admin/config/search/apachesolr/settings/' . $form_state['values']['env_id'] . '/clone';
 }
 
 /**
  * Form builder for adding/editing a Solr environment used as a menu callback.
  */
-function apachesolr_environment_edit_form($form, &$form_state, $environment = NULL) {
+function apachesolr_environment_edit_form(array $form, array &$form_state, array $environment = array()) {
   if (empty($environment)) {
     $environment = array();
   }
@@ -191,7 +229,13 @@ function apachesolr_environment_edit_form($form, &$form_state, $environment = NU
   return $form;
 }
 
-function apachesolr_environment_edit_test_submit($form, &$form_state) {
+/**
+ * Submit handler for the test button in the environment edit page
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_edit_test_submit(array $form, array &$form_state) {
   $ping = apachesolr_server_status($form_state['values']['url'], $form_state['values']['service_class']);
   if ($ping) {
     drupal_set_message(t('Your site has contacted the Apache Solr server.'));
@@ -202,7 +246,13 @@ function apachesolr_environment_edit_test_submit($form, &$form_state) {
   $form_state['rebuild'] = TRUE;
 }
 
-function apachesolr_environment_edit_validate($form, &$form_state) {
+/**
+ * Validate handler for the environment edit page
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_edit_validate(array $form, array &$form_state) {
   $parts = parse_url($form_state['values']['url']);
   foreach (array('scheme', 'host', 'path') as $key) {
     if (empty($parts[$key])) {
@@ -224,7 +274,13 @@ function apachesolr_environment_edit_validate($form, &$form_state) {
   }
 }
 
-function apachesolr_environment_edit_submit($form, &$form_state) {
+/**
+ * Submit handler for the environment  edit page
+ *
+ * @param array $form
+ * @param array $form_state
+ */
+function apachesolr_environment_edit_submit(array $form, array &$form_state) {
   apachesolr_environment_save($form_state['values']);
   if (!empty($form_state['values']['make_default'])) {
     apachesolr_set_default_environment($form_state['values']['env_id']);
@@ -265,8 +321,13 @@ function apachesolr_check_facetapi() {
 
 /**
  * Form builder for general settings used as a menu callback.
+ *
+ * @param array $form
+ * @param array $form_state
+ *
+ * @return array Output of the system_settings_form()
  */
-function apachesolr_settings($form, &$form_state) {
+function apachesolr_settings(array $form, array &$form_state) {
   $form = array();
   $rows = array();
 
@@ -455,8 +516,13 @@ function apachesolr_settings($form, &$form_state) {
 
 /**
  * Gets information about the fields already in solr index.
+ *
+ * @param array $environment
+ *   The environment for which we need to ask the status from
+ *
+ * @return array page render array
  */
-function apachesolr_status_page($environment = NULL) {
+function apachesolr_status_page(array $environment = array()) {
   if (empty($environment)) {
     $env_id = apachesolr_default_environment();
     $environment = apachesolr_environment_load($env_id);
@@ -553,8 +619,15 @@ function apachesolr_status_page($environment = NULL) {
   return $output;
 }
 
-function apachesolr_index_report($environment = NULL) {
-  if (!$environment) {
+/**
+ * Get the report, eg.: some statistics and useful data from the Apache Solr index
+ *
+ * @param array $environment
+ *
+ * @return array page render array
+ */
+function apachesolr_index_report(array $environment = array()) {
+  if (empty($environment)) {
     $env_id = apachesolr_default_environment();
     drupal_goto('admin/reports/apachesolr/' . $env_id);
   }
@@ -651,9 +724,14 @@ function apachesolr_index_report($environment = NULL) {
 
 /**
  * Page callback to show available conf files.
+ *
+ * @param array $environment
+ *
+ * @return string
+ *   A non-render array but plain theme output for the config files overview. Could be done better probably
  */
-function apachesolr_config_files_overview($environment = NULL) {
-  if (!$environment) {
+function apachesolr_config_files_overview(array $environment = array()) {
+  if (empty($environment)) {
     $env_id = apachesolr_default_environment();
   }
   else {
@@ -724,9 +802,15 @@ function apachesolr_config_files_overview($environment = NULL) {
 
 /**
  * Page callback to show one conf file.
+ *
+ * @param string $name
+ * @param array $environment
+ *
+ * @return string
+ *   the requested config file
  */
-function apachesolr_config_file($name, $environment = NULL) {
-  if (!$environment) {
+function apachesolr_config_file($name, array $environment = array()) {
+  if (empty($environment)) {
     $env_id = apachesolr_default_environment();
   }
   else {
@@ -751,9 +835,15 @@ function apachesolr_config_file($name, $environment = NULL) {
 /**
  * Form builder for the Apachesolr Indexer actions form.
  *
+ * @param array $form
+ * @param array $form_state
+ * @param string $env_id
+ *   The machine name of the environment.
  * @see apachesolr_index_action_form_delete_submit().
+ *
+ * @return array $form
  */
-function apachesolr_index_action_form($form, $form_state, $env_id) {
+function apachesolr_index_action_form(array $form, array $form_state, $env_id) {
   $form = array();
   $form['action'] = array(
     '#type' => 'fieldset',
@@ -814,8 +904,11 @@ function apachesolr_index_action_form($form, $form_state, $env_id) {
 
 /**
  * Submit handler for the Indexer actions form, delete button.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_remaining_submit($form, &$form_state) {
+function apachesolr_index_action_form_remaining_submit(array $form, array &$form_state) {
   $destination = array();
   if (isset($_GET['destination'])) {
     $destination = drupal_get_destination();
@@ -827,8 +920,11 @@ function apachesolr_index_action_form_remaining_submit($form, &$form_state) {
 
 /**
  * Submit handler for the Indexer actions form, delete button.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_delete_submit($form, &$form_state) {
+function apachesolr_index_action_form_delete_submit(array $form, array &$form_state) {
   $destination = array();
   if (isset($_GET['destination'])) {
     $destination = drupal_get_destination();
@@ -840,8 +936,11 @@ function apachesolr_index_action_form_delete_submit($form, &$form_state) {
 
 /**
  * Submit handler for the Indexer actions form, delete button.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_reset_submit($form, &$form_state) {
+function apachesolr_index_action_form_reset_submit(array $form, array &$form_state) {
   $destination = array();
   if (isset($_GET['destination'])) {
     $destination = drupal_get_destination();
@@ -851,11 +950,13 @@ function apachesolr_index_action_form_reset_submit($form, &$form_state) {
   $form_state['redirect'] = array('admin/config/search/apachesolr/settings/' . $env_id . '/index/reset', array('query' => $destination));
 }
 
-
 /**
  * Submit handler for the deletion form.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_cron_submit($form, &$form_state) {
+function apachesolr_index_action_form_cron_submit(array $form, array &$form_state) {
   if (!empty($form_state['build_info']['args'][0])) {
     $env_id = $form_state['build_info']['args'][0];
   }
@@ -868,11 +969,17 @@ function apachesolr_index_action_form_cron_submit($form, &$form_state) {
 }
 
 /**
- * Form builder for to reindex the remaining.
+ * Form builder for to reindex the remaining items left in the queue.
  *
  * @see apachesolr_index_action_form_delete_confirm_submit().
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return mixed
  */
-function apachesolr_index_action_form_remaining_confirm($form, &$form_state, $environment) {
+function apachesolr_index_action_form_remaining_confirm(array $form, array &$form_state, array $environment) {
   return confirm_form($form,
     t('Are you sure you want index all remaining content?'),
     'admin/config/search/apachesolr/settings/' . $environment['env_id'] . '/index',
@@ -883,8 +990,11 @@ function apachesolr_index_action_form_remaining_confirm($form, &$form_state, $en
 
 /**
  * Submit handler for the deletion form.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_remaining_confirm_submit($form, &$form_state) {
+function apachesolr_index_action_form_remaining_confirm_submit(array $form, array &$form_state) {
   if (!empty($form_state['build_info']['args'][0]['env_id'])) {
     $env_id = $form_state['build_info']['args'][0]['env_id'];
   }
@@ -899,8 +1009,14 @@ function apachesolr_index_action_form_remaining_confirm_submit($form, &$form_sta
  * Form builder for the index re-enqueue form.
  *
  * @see apachesolr_index_action_form_reset_confirm_submit().
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return mixed
  */
-function apachesolr_index_action_form_reset_confirm($form, &$form_state, $environment) {
+function apachesolr_index_action_form_reset_confirm(array $form, array &$form_state, array $environment) {
   return confirm_form($form,
     t('Are you sure you want to queue content for reindexing?'),
     'admin/config/search/apachesolr/settings/' . $environment['env_id'] . '/index',
@@ -911,8 +1027,11 @@ function apachesolr_index_action_form_reset_confirm($form, &$form_state, $enviro
 
 /**
  * Submit handler for the deletion form.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_reset_confirm_submit($form, &$form_state) {
+function apachesolr_index_action_form_reset_confirm_submit(array $form, array &$form_state) {
   if (!empty($form_state['build_info']['args'][0]['env_id'])) {
     $env_id = $form_state['build_info']['args'][0]['env_id'];
   }
@@ -929,8 +1048,14 @@ function apachesolr_index_action_form_reset_confirm_submit($form, &$form_state)
  * Form builder for the index delete/clear form.
  *
  * @see apachesolr_index_action_form_delete_confirm_submit().
+
+ * @param array $form
+ * @param array $form_state
+ * @param array $environment
+ *
+ * @return array output of confirm_form()
  */
-function apachesolr_index_action_form_delete_confirm($form, &$form_state, $environment) {
+function apachesolr_index_action_form_delete_confirm(array $form, array &$form_state, array $environment) {
   return confirm_form($form,
     t('Are you sure you want to clear your index?'),
     'admin/config/search/apachesolr/settings/' . $environment['env_id'] . '/index',
@@ -941,8 +1066,11 @@ function apachesolr_index_action_form_delete_confirm($form, &$form_state, $envir
 
 /**
  * Submit handler for the deletion form.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_action_form_delete_confirm_submit($form, &$form_state) {
+function apachesolr_index_action_form_delete_confirm_submit(array $form, array &$form_state) {
   if (!empty($form_state['build_info']['args'][0]['env_id'])) {
     $env_id = $form_state['build_info']['args'][0]['env_id'];
   }
@@ -958,7 +1086,10 @@ function apachesolr_index_action_form_delete_confirm_submit($form, &$form_state)
 }
 
 /**
- * Submit a batch job to index the remaining, unindexed content.
+ * Submit a batch job to index the remaining, non-indexed content.
+ *
+ * @param string $env_id
+ *   The environment ID where it needs to index the remaining items for
  */
 function apachesolr_index_batch_index_remaining($env_id, $total_limit = null) {
   $batch = array(
@@ -981,14 +1112,21 @@ function apachesolr_index_batch_index_remaining($env_id, $total_limit = null) {
   batch_set($batch);
 }
 
+
 /**
  * Batch Operation Callback
  *
- * @param $env_id
- *   The machine name of the environment
+ * @param string $env_id
+ *   The machine name of the environment.
  * @param $total_limit
  *   The total number of items to index across all batches
- * @param $context
+ * @param array $context
+ *
+ * @return false
+ *   return false when an exception was caught
+ *
+ * @throws Exception
+ *   When solr gives an error, throw an exception that solr is not available
  */
 function apachesolr_index_batch_index_entities($env_id, $total_limit = NULL, &$context) {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
@@ -1057,8 +1195,13 @@ function apachesolr_index_batch_index_entities($env_id, $total_limit = NULL, &$c
 
 /**
  * Batch 'finished' callback
+ *
+ * @param bool $success
+ *   Whether the batch ended with success or not
+ * @param array $results
+ * @param array $operations
  */
-function apachesolr_index_batch_index_finished($success, $results, $operations) {
+function apachesolr_index_batch_index_finished($success, array $results, array $operations) {
   $message = '';
   // $results['count'] will not be set if Solr is unavailable.
   if (isset($results['count'])) {
@@ -1079,13 +1222,19 @@ function apachesolr_index_batch_index_finished($success, $results, $operations)
   drupal_set_message($message, $type);
 }
 
-
 /**
  * Form builder for the bundle configuration form.
  *
  * @see apachesolr_index_config_form_submit().
+ *
+ * @param array $form
+ * @param array $form_state
+ * @param string $env_id
+ *   The machine name of the environment.
+ *
+ * @return array $form
  */
-function apachesolr_index_config_form($form, $form_state, $env_id) {
+function apachesolr_index_config_form(array $form, array $form_state, $env_id) {
   $form['config'] = array(
     '#type' => 'fieldset',
     '#title' => t('Configuration'),
@@ -1127,8 +1276,11 @@ function apachesolr_index_config_form($form, $form_state, $env_id) {
 
 /**
  * Submit handler for the bundle configuration form.
+ *
+ * @param array $form
+ * @param array $form_state
  */
-function apachesolr_index_config_form_submit($form, &$form_state) {
+function apachesolr_index_config_form_submit(array $form, array &$form_state) {
   module_load_include('inc', 'apachesolr', 'apachesolr.index');
   $form_values = $form_state['values'];
   $env_id = $form_values['env_id'];
@@ -1162,6 +1314,9 @@ function apachesolr_index_config_form_submit($form, &$form_state) {
 
 /**
  * Page callback for node/%node/devel/apachesolr.
+ *
+ * @param object $node
+ * @return string debugging information
  */
 function apachesolr_devel($node) {
   $item = new stdClass();
@@ -1178,4 +1333,4 @@ function apachesolr_devel($node) {
     $output .= kdevel_print_object($debug_data);
   }
   return $output;
-}
\ No newline at end of file
+}
diff --git a/apachesolr.api.php b/apachesolr.api.php
index 4851434..9769043 100644
--- a/apachesolr.api.php
+++ b/apachesolr.api.php
@@ -6,6 +6,11 @@
 
 /**
  * Lets modules know when the default environment is changed.
+ *
+ * @param string $env_id
+ *   The machine name of the environment.
+ * @param string $old_env_id
+ *   The old machine name of the environment.
  */
 function hook_apachesolr_default_environment($env_id, $old_env_id) {
   $page = apachesolr_search_page_load('core_search');
@@ -114,8 +119,10 @@ function hook_apachesolr_field_mappings() {
  * @param array $mappings
  *   An associative array of mappings as defined by modules that implement
  *   hook_apachesolr_field_mappings().
+ * @param string $entity_type
+ *   The entity type for which you want to alter the field mappings
  */
-function hook_apachesolr_field_mappings_alter(&$mappings, $entity_type) {
+function hook_apachesolr_field_mappings_alter(array &$mappings, $entity_type) {
   // Enable indexing for text fields
   $mappings['text'] = array(
     'indexing_callback' => 'apachesolr_fields_default_indexing_callback',
@@ -148,10 +155,10 @@ function hook_apachesolr_field_mappings_alter(&$mappings, $entity_type) {
  * This is otherwise the same as HOOK_apachesolr_query_alter(), but runs before
  * it.
  *
- * @param object $query
+ * @param DrupalSolrQueryInterface $query
  *  An object implementing DrupalSolrQueryInterface. No need for &.
  */
-function hook_apachesolr_query_prepare($query) {
+function hook_apachesolr_query_prepare(DrupalSolrQueryInterface $query) {
   // Add a sort on the node ID.
   $query->setAvailableSort('entity_id', array(
     'title' => t('Node ID'),
@@ -164,7 +171,7 @@ function hook_apachesolr_query_prepare($query) {
  *
  * @param array $map
  */
-function hook_apachesolr_field_name_map_alter(&$map) {
+function hook_apachesolr_field_name_map_alter(array &$map) {
   $map['xs_node'] = t('The full node object');
 }
 
@@ -178,10 +185,10 @@ function hook_apachesolr_field_name_map_alter(&$map) {
  * A module implementing HOOK_apachesolr_query_alter() may set
  * $query->abort_search to TRUE to flag the query to be aborted.
  *
- * @param object $query
+ * @param DrupalSolrQueryInterface $query
  *   An object implementing DrupalSolrQueryInterface. No need for &.
  */
-function hook_apachesolr_query_alter($query) {
+function hook_apachesolr_query_alter(DrupalSolrQueryInterface $query) {
   // I only want to see articles by the admin.
   //
   // NOTE: this "is_uid" filter does NOT refer to the English word "is"
@@ -200,6 +207,7 @@ function hook_apachesolr_query_alter($query) {
  *
  * @param string $query
  *   Defaults to *:*
+ *   This is not an instance of DrupalSolrQueryInterface, it is the raw query that is being sent to Solr
  */
 function hook_apachesolr_delete_by_query_alter($query) {
   // use the site hash so that you only delete this site's content
@@ -222,14 +230,15 @@ function hook_apachesolr_delete_by_query_alter($query) {
  * This is invoked for each entity that is being inspected to be added to the
  * index. if any module returns TRUE, the entity is skipped for indexing.
  *
- * @param integer $entity_id
+ * @param string $entity_id
  * @param string $entity_type
- * @param integer $row
+ * @param array $row
  *   A complete set of data from the indexing table.
  * @param string $env_id
+ *   The machine name of the environment.
  * @return boolean
  */
-function hook_apachesolr_exclude($entity_id, $entity_type, $row, $env_id) {
+function hook_apachesolr_exclude($entity_id, $entity_type, array $row, $env_id) {
   // Never index media entities to core_1
   if ($entity_type == 'media' && $env_id == 'core_1') {
     return TRUE;
@@ -242,13 +251,14 @@ function hook_apachesolr_exclude($entity_id, $entity_type, $row, $env_id) {
  * inspected to be added to the index. if any module returns TRUE, 
  * the entity is skipped for indexing.
  *
- * @param integer $entity_id
- * @param integer $row
+ * @param string $entity_id
+ * @param array $row
  *   A complete set of data from the indexing table.
  * @param string $env_id
+ *   The machine name of the environment.
  * @return boolean
  */
-function hook_apachesolr_ENTITY_TYPE_exclude($entity_id, $row, $env_id) {
+function hook_apachesolr_ENTITY_TYPE_exclude($entity_id, array $row, $env_id) {
   // Never index ENTITY_TYPE to core_1
   if ($env_id == 'core_1') {
     return TRUE;
@@ -263,7 +273,7 @@ function hook_apachesolr_ENTITY_TYPE_exclude($entity_id, $row, $env_id) {
  *
  * @param array $entity_info
  */
-function hook_apachesolr_entity_info_alter(&$entity_info) {
+function hook_apachesolr_entity_info_alter(array &$entity_info) {
   // REQUIRED VALUES
   // myentity should be replaced with user/node/custom entity
   $entity_info['node'] = array();
@@ -301,12 +311,12 @@ function hook_apachesolr_entity_info_alter(&$entity_info) {
  * search. This has been introduced in 6.x-beta7 as a replacement for the call
  * to HOOK_nodeapi().
  *
- * @param object $document
+ * @param ApacheSolrDocument $document
  *   The ApacheSolrDocument instance.
  * @param array $extra
- * @param array $query
+ * @param DrupalSolrQueryInterface $query
  */
-function hook_apachesolr_search_result_alter($document, &$extra, DrupalSolrQueryInterface $query) {
+function hook_apachesolr_search_result_alter(ApacheSolrDocument $document, array &$extra, DrupalSolrQueryInterface $query) {
 }
 
 /**
@@ -315,8 +325,10 @@ function hook_apachesolr_search_result_alter($document, &$extra, DrupalSolrQuery
  *
  * @param array $results
  *   The returned search results.
+ * @param DrupalSolrQueryInterface $query
+ *   The query for which we want to process the results from
  */
-function hook_apachesolr_process_results(&$results, DrupalSolrQueryInterface $query) {
+function hook_apachesolr_process_results(array &$results, DrupalSolrQueryInterface $query) {
   foreach ($results as $id => $result) {
     $results[$id]['title'] = t('[Result] !title', array('!title' => $result['title']));
   }
@@ -331,7 +343,7 @@ function hook_apachesolr_process_results(&$results, DrupalSolrQueryInterface $qu
  * @param array $environment
  *   The environment object that is being deleted.
  */
-function hook_apachesolr_environment_delete($environment) {
+function hook_apachesolr_environment_delete(array $environment) {
 }
 
 /**
@@ -343,7 +355,7 @@ function hook_apachesolr_environment_delete($environment) {
  * @param array $build
  * @param array $search_page
  */
-function hook_apachesolr_search_page_alter(&$build, $search_page) {
+function hook_apachesolr_search_page_alter(array &$build, array $search_page) {
   // Adds a text to the top of the page
   $info = array('#markup' => t('Add information to every search page'));
   array_unshift($build, $info);
@@ -366,9 +378,11 @@ function hook_apachesolr_search_types_alter(&$search_types) {
  * Build the documents before sending them to Solr.
  * The function is the follow-up for apachesolr_update_index
  *
- * @param integer $document_id
- * @param array $entity
+ * @param ApacheSolrDocument $document
+ * @param object $entity
  * @param string $entity_type
+ * @param string $env_id
+ *   The machine name of the environment.
  */
 function hook_apachesolr_index_document_build(ApacheSolrDocument $document, $entity, $entity_type, $env_id) {
 
@@ -383,9 +397,10 @@ function hook_apachesolr_index_document_build(ApacheSolrDocument $document, $ent
  * The function is the follow-up for apachesolr_update_index but then for
  * specific entity types
  *
- * @param $document
- * @param $entity
- * @param $entity_type
+ * @param ApacheSolrDocument $document
+ * @param object $entity
+ * @param string $env_id
+ *   The machine name of the environment.
  */
 function hook_apachesolr_index_document_build_ENTITY_TYPE(ApacheSolrDocument $document, $entity, $env_id) {
   // Index field_main_image as a separate field
@@ -401,9 +416,10 @@ function hook_apachesolr_index_document_build_ENTITY_TYPE(ApacheSolrDocument $do
  *
  * @param $documents
  *   Array of ApacheSolrDocument objects.
- * @param $entity
- * @param $entity_type
+ * @param object $entity
+ * @param string $entity_type
  * @param string $env_id
+ *   The machine name of the environment.
  */
 function hook_apachesolr_index_documents_alter(array &$documents, $entity, $entity_type, $env_id) {
   // Do whatever altering you need here
diff --git a/apachesolr.index.inc b/apachesolr.index.inc
index c551299..e4331c7 100644
--- a/apachesolr.index.inc
+++ b/apachesolr.index.inc
@@ -27,7 +27,7 @@
  *   100 documents to the Apache Solr server.
  *
  * @return int
- *   The total numer of documents sent to the Apache Solr server for indexing.
+ *   The total number of documents sent to the Apache Solr server for indexing.
  *
  * @see apachesolr_index_get_entities_to_index()
  * @see apachesolr_index_entity_to_documents()
@@ -67,7 +67,20 @@ function apachesolr_index_entities($env_id, $limit) {
   return $documents_submitted;
 }
 
-function apachesolr_index_entities_document($row, $entity_type, $env_id) {
+/**
+ * Convert a certain entity from the apachesolr index table to a set of documents. 1 entity
+ * can be converted in multiple documents if the apachesolr_index_entity_to_documents decides to do so.
+ *
+ * @param $row
+ *   A row from the indexing table
+ * @param $entity_type
+ *   The type of the entity
+ * @param $env_id
+ *   The machine name of the environment.
+ *
+ * @return array of ApacheSolrDocument(s)
+ */
+function apachesolr_index_entities_document(array $row, $entity_type, $env_id) {
   $documents = array();
   if (!empty($row->status)) {
     // Let any module exclude this entity from the index.
@@ -128,8 +141,11 @@ function apachesolr_index_status($env_id) {
     $query = db_select($table, 'asn')->condition('asn.status', 1)->condition('asn.bundle', $bundles);
     $total += $query->countQuery()->execute()->fetchField();
 
-    // Get $last_entity_id and $last_change.
-    extract(apachesolr_get_last_index_position($env_id, $entity_type));
+    // Get $last_entity_id and $last_changed.
+    $last_index_position = apachesolr_get_last_index_position($env_id, $entity_type);
+    $last_entity_id = $last_index_position['last_entity_id'];
+    $last_changed = $last_index_position['last_changed'];
+
     // Find the next batch of entities to index for this entity type.  Note that
     // for ordering we're grabbing the oldest first and then ordering by ID so
     // that we get a definitive order.
@@ -193,15 +209,11 @@ function apachesolr_index_status($env_id) {
  * @see apachesolr_index_nodes() for the old-skool version.
  */
 function apachesolr_index_entity_to_documents($item, $env_id) {
-
-  // Always build the content for the index as an anonynmous user to avoid
-  // exposing restricted fields and such.
-  // @todo Uncomment these lines when we're done debugging, since they break dpm().
   global $user;
   drupal_save_session(FALSE);
   $saved_user = $user;
-  // Should indexing take place using anon ( default )
-  // or as another user
+  // build the content for the index as an anonymous user to avoid exposing restricted fields and such.
+  // By setting a variable, indexing can take place as a different user
   $uid = variable_get('apachesolr_index_user', 0);
   if ($uid == 0) {
     $user = drupal_anonymous_user();
@@ -284,9 +296,13 @@ function apachesolr_index_entity_to_documents($item, $env_id) {
 /**
  * Index an array of documents to solr.
  *
- * @return number indexed, or FALSE on failure.
+ * @param $env_id
+ * @param array $documents
+ *
+ * @return bool|int number indexed, or FALSE on failure.
+ * @throws Exception
  */
-function apachesolr_index_send_to_solr($env_id, $documents) {
+function apachesolr_index_send_to_solr($env_id, array $documents) {
   try {
     // Get the $solr object
     $solr = apachesolr_get_solr($env_id);
@@ -333,9 +349,12 @@ function apachesolr_index_send_to_solr($env_id, $documents) {
 /**
  * Extract HTML tag contents from $text and add to boost fields.
  *
- * $text must be stripped of control characters before hand.
+ * @param ApacheSolrDocument $document
+ * @param string $text
+ *   must be stripped of control characters before hand.
+ *
  */
-function apachesolr_index_add_tags_to_document($document, $text) {
+function apachesolr_index_add_tags_to_document(ApacheSolrDocument $document, $text) {
   $tags_to_index = variable_get('apachesolr_tags_to_index', array(
     'h1' => 'tags_h1',
     'h2' => 'tags_h2_h3',
@@ -374,7 +393,7 @@ function apachesolr_index_add_tags_to_document($document, $text) {
  * to all entities, but virtually all entities will need their own additional
  * processing.
  *
- * @param stdClass $entity
+ * @param object $entity
  *   The entity for which we want a document.
  * @param string $entity_type
  *   The type of entity we're processing.
@@ -432,6 +451,12 @@ function _apachesolr_index_process_entity_get_document($entity, $entity_type) {
 /**
  * Returns an array of rows from a query based on an indexing environment.
  * @todo Remove the read only because it is not environment specific
+ *
+ * @param $env_id
+ * @param $entity_type
+ * @param $limit
+ *
+ * @return array list of row to index
  */
 function apachesolr_index_get_entities_to_index($env_id, $entity_type, $limit) {
   $rows = array();
@@ -444,8 +469,11 @@ function apachesolr_index_get_entities_to_index($env_id, $entity_type, $limit) {
   }
 
   $table = apachesolr_get_indexer_table($entity_type);
-  // Get $last_entity_id and $last_change.
-  extract(apachesolr_get_last_index_position($env_id, $entity_type));
+  // Get $last_entity_id and $last_changed.
+  $last_index_position = apachesolr_get_last_index_position($env_id, $entity_type);
+  $last_entity_id = $last_index_position['last_entity_id'];
+  $last_changed = $last_index_position['last_changed'];
+
   // Find the next batch of entities to index for this entity type.  Note that
   // for ordering we're grabbing the oldest first and then ordering by ID so
   // that we get a definitive order.
@@ -490,7 +518,7 @@ function apachesolr_index_get_entities_to_index($env_id, $entity_type, $limit) {
  * Delete the whole index for an environment.
  *
  * @param string $env_id
- *   The solr environment indentifier.
+ *   The machine name of the environment.
  * @param string $entity_type
  *   (optional) specify to remove just this entity_type from the index.
  * @param string $bundle
@@ -540,10 +568,11 @@ function apachesolr_index_delete_index($env_id, $entity_type = NULL, $bundle = N
  * Also deletes all documents that have the entity type and bundle as a parent.
  *
  * @param string $env_id
+ *   The machine name of the environment.
  * @param string $entity_type
  * @param array $excluded_bundles
  *
- * @return TRUE on success, FALSE on failure.
+ * @return true on success, false on failure.
  */
 function apachesolr_index_delete_bundles($env_id, $entity_type, array $excluded_bundles) {
   // Remove newly omitted bundles.
@@ -575,10 +604,11 @@ function apachesolr_index_delete_bundles($env_id, $entity_type, array $excluded_
  * Also deletes all documents that have the deleted document as a parent.
  *
  * @param string $env_id
+ *   The machine name of the environment.
  * @param string $entity_type
  * @param string $entity_id
  *
- * @return TRUE on success, FALSE on failure.
+ * @return true on success, false on failure.
  */
 function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entity_id) {
   static $failed = FALSE;
@@ -602,9 +632,10 @@ function apachesolr_index_delete_entity_from_index($env_id, $entity_type, $entit
 }
 
 /**
- * @param $entity_type
+ * Mark a certain entity type for a specific environment for reindexing.
  *
- * @throws Exception
+ * @param $env_id
+ * @param null $entity_type
  */
 function apachesolr_index_mark_for_reindex($env_id, $entity_type = NULL) {
   foreach (entity_get_info() as $type => $entity_info) {
@@ -625,7 +656,7 @@ function apachesolr_index_mark_for_reindex($env_id, $entity_type = NULL) {
  * Sets what bundles on the specified entity type should be indexed.
  *
  * @param string $env_id
- *   The Solr core for which to index entities.
+ *   The machine name of the environment.
  * @param string $entity_type
  *   The entity type to index.
  * @param array $bundles
@@ -670,10 +701,10 @@ if (!function_exists('entity_bundle_label')) {
 /**
  * Returns the label of a bundle.
  *
- * @param $entity_type
+ * @param string $entity_type
  *   The entity type; e.g. 'node' or 'user'.
- * @param $entity
- *   The entity for which we want the human-readable label of its bundle.
+ * @param string $bundle_name
+ *   The bundle for which we want the label from
  *
  * @return
  *   A string with the human-readable name of the bundle, or FALSE if not specified.
@@ -694,20 +725,19 @@ function entity_bundle_label($entity_type, $bundle_name) {
 
 }
 
-
-/************************
- * The NODE entity indexing part
- ************************/
-
 /**
  * Builds the node-specific information for a Solr document.
  *
  * @param ApacheSolrDocument $document
  *   The Solr document we are building up.
- * @param stdClass $entity
+ * @param object $node
  *   The entity we are indexing.
  * @param string $entity_type
  *   The type of entity we're dealing with.
+ * @param string $env_id
+ *   The type of entity we're dealing with.
+ *
+ * @return array A set of ApacheSolrDocument documents
  */
 function apachesolr_index_node_solr_document(ApacheSolrDocument $document, $node, $entity_type, $env_id) {
   // None of these get added unless they are explicitly in our schema.xml
@@ -815,14 +845,21 @@ function apachesolr_index_node_solr_document(ApacheSolrDocument $document, $node
     $document->tos_content_extra = apachesolr_clean_text(implode(' ', $extra));
   }
 
-  //  Generic usecase for future reference. Callbacks can
+  //  Generic use case for future reference. Callbacks can
   //  allow you to send back multiple documents
   $documents = array();
   $documents[] = $document;
   return $documents;
 }
 
-
+/**
+ * Function that will be executed if the node bundles were updated.
+ * Currently it does nothing, but it could potentially do something later on.
+ *
+ * @param $env_id
+ * @param $existing_bundles
+ * @param $new_bundles
+ */
 function apachesolr_index_node_bundles_changed($env_id, $existing_bundles, $new_bundles) {
   // Nothing to do for now.
 }
@@ -831,10 +868,13 @@ function apachesolr_index_node_bundles_changed($env_id, $existing_bundles, $new_
  * Reindexing callback for ApacheSolr, for nodes.
  *
  * @param string $env_id
- *   The solr environment
+ *   The machine name of the environment.
  * @param string|null $bundle
  *   (optional) The bundle type to reindex. If not used
- *   all bundles will be reindexed.
+ *   all bundles will be re-indexed.
+ *
+ * @return null
+ *   returns NULL if the specified bundle is not in the indexable bundles list
  *
  * @throws Exception
  */
@@ -857,7 +897,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');
@@ -890,6 +930,13 @@ function apachesolr_index_node_solr_reindex($env_id, $bundle = NULL) {
 
 /**
  * Status callback for ApacheSolr, for nodes.
+ * after indexing a certain amount of nodes
+ *
+ * @param $entity_id
+ * @param $entity_type
+ *
+ * @return int
+ *   The status of the node
  */
 function apachesolr_index_node_status_callback($entity_id, $entity_type) {
   // Make sure we have a boolean value.
@@ -905,7 +952,6 @@ function apachesolr_index_node_status_callback($entity_id, $entity_type) {
   return $status;
 }
 
-
 /**
  * Callback that converts term_reference field into an array
  */
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 a32c932..822283d 100644
--- a/drush/apachesolr.drush.inc
+++ b/drush/apachesolr.drush.inc
@@ -185,16 +185,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 '';
 }
 
 /**
@@ -234,6 +241,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();
@@ -252,6 +262,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');
@@ -264,6 +277,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();
@@ -282,6 +301,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);
@@ -297,6 +319,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');
 
@@ -311,6 +336,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 {
@@ -322,6 +355,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 {
@@ -333,6 +374,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 {
@@ -345,11 +394,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;
@@ -380,6 +433,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();
@@ -442,6 +500,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)) {
@@ -481,6 +548,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) {
 
@@ -523,6 +593,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) {
@@ -537,7 +610,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) {
   }
 }
 
