From 7c1e0c6c48fc6ef442efca735a76f8a5de46b425 Mon Sep 17 00:00:00 2001
From: Dave Hall <dave.hall@skwashd.com>
Date: Thu, 12 Jun 2014 09:20:13 +1000
Subject: [PATCH] Issue #2284737 by skwashd: Fix issues found by coder-review
 and variable_get() calls

---
 includes/pages/slack.admin.inc | 18 +++++++++++++-----
 includes/pages/slack.pages.inc | 21 ++++++++++++++++-----
 includes/slack.api.inc         | 11 ++++++++---
 slack.rules.inc                | 11 ++++++++---
 4 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/includes/pages/slack.admin.inc b/includes/pages/slack.admin.inc
index e98e1af..2474260 100644
--- a/includes/pages/slack.admin.inc
+++ b/includes/pages/slack.admin.inc
@@ -1,30 +1,38 @@
 <?php
 
+/**
+ * @file
+ * Slack integration module admin functions.
+ */
+
+/**
+ * Slack module admin form.
+ */
 function slack_configure_form($form, &$form_state) {
   $form['slack_team'] = array(
     '#type' => 'textfield',
     '#title' => t('Team name'),
-    '#default_value' => variable_get('slack_team', ''),
+    '#default_value' => slack_get_default_team_name(),
     '#required' => TRUE,
   );
   $form['slack_token'] = array(
     '#type' => 'textfield',
     '#title' => t('Team token'),
     '#description' => t('Add the "Incoming WebHooks" integration in the Slack and take the token there.'),
-    '#default_value' => variable_get('slack_token', ''),
+    '#default_value' => slack_get_default_team_token(),
     '#required' => TRUE,
   );
   $form['slack_channel'] = array(
     '#type' => 'textfield',
     '#title' => t('Default channel'),
     '#description' => t('Enter your channel name with # symbol, for example #general.'),
-    '#default_value' => variable_get('slack_channel', ''),
+    '#default_value' => variable_get('slack_channel'),
   );
   $form['slack_username'] = array(
     '#type' => 'textfield',
     '#title' => t('Default username'),
     '#description' => t('What would you like to name your Slack bot?'),
-    '#default_value' => variable_get('slack_username', ''),
+    '#default_value' => variable_get('slack_username'),
   );
   return system_settings_form($form);
-}
\ No newline at end of file
+}
diff --git a/includes/pages/slack.pages.inc b/includes/pages/slack.pages.inc
index 2f38154..c3463f7 100644
--- a/includes/pages/slack.pages.inc
+++ b/includes/pages/slack.pages.inc
@@ -1,15 +1,23 @@
 <?php
 
+/**
+ * @file
+ * Slack module page functions.
+ */
+
+/**
+ * Slack test message form.
+ */
 function slack_send_test_message_form($form, &$form_state) {
   $form['slack_test_channel'] = array(
     '#type' => 'textfield',
     '#title' => t('Channel'),
-    '#default_value' => variable_get('slack_channel', ''),
+    '#default_value' => variable_get('slack_channel'),
   );
   $form['slack_test_username'] = array(
     '#type' => 'textfield',
     '#title' => t('Username'),
-    '#default_value' => variable_get('slack_username', ''),
+    '#default_value' => variable_get('slack_username'),
   );
   $form['slack_test_message'] = array(
     '#type' => 'textarea',
@@ -23,18 +31,21 @@ function slack_send_test_message_form($form, &$form_state) {
   return $form;
 }
 
+/**
+ * Submit handler for slack test message form.
+ */
 function slack_send_test_message_form_submit($form, &$form_state) {
   $channel = $form_state['values']['slack_test_channel'];
   $username = $form_state['values']['slack_test_username'];
   $message = $form_state['values']['slack_test_message'];
   $result = slack_send_message($message, $channel, $username);
   if (!$result) {
-    drupal_set_message(t('Message wasn\'t sent. Please, check slack module configuration.'));
+    drupal_set_message(t("Message wasn't sent. Please, check slack module configuration."));
   }
   elseif (!isset($result->error) && $result->code == SLACK_CODE_OK) {
     drupal_set_message(t('Message was successfully sent.'));
   }
   else {
-    drupal_set_message(t('Message wasn\'t sent.'), 'error');
+    drupal_set_message(t("Message wasn't sent."), 'error');
   }
-}
\ No newline at end of file
+}
diff --git a/includes/slack.api.inc b/includes/slack.api.inc
index 460af8a..76e1e9a 100644
--- a/includes/slack.api.inc
+++ b/includes/slack.api.inc
@@ -1,6 +1,11 @@
 <?php
 
 /**
+ * @file
+ * Slack integration module API functions.
+ */
+
+/**
  * @param string $message
  *   The message sent to the channel
  * @param string $channel
@@ -69,7 +74,7 @@ function _slack_send_message($team_name, $team_token, $message, $message_options
  *   Get default team name
  */
 function slack_get_default_team_name() {
-  $team_name = variable_get('slack_team', '');
+  $team_name = variable_get('slack_team');
   return $team_name;
 }
 
@@ -78,6 +83,6 @@ function slack_get_default_team_name() {
  *   Get default team token
  */
 function slack_get_default_team_token() {
-  $team_token = variable_get('slack_token', '');
+  $team_token = variable_get('slack_token');
   return $team_token;
-}
\ No newline at end of file
+}
diff --git a/slack.rules.inc b/slack.rules.inc
index 292d650..e6f1728 100644
--- a/slack.rules.inc
+++ b/slack.rules.inc
@@ -1,6 +1,11 @@
 <?php
 
 /**
+ * @file
+ * Slack integration module rules functions.
+ */
+
+/**
  * Implements hook_rules_action_info().
  */
 function slack_rules_action_info() {
@@ -36,10 +41,10 @@ function slack_rules_action_info() {
  */
 function slack_rules_send_message_action($message, $channel, $username) {
   if (!$channel) {
-    $channel = variable_get('slack_channel', '');
+    $channel = variable_get('slack_channel');
   }
   if (!$username) {
-    $username = variable_get('slack_username', '');
+    $username = variable_get('slack_username');
   }
   slack_send_message($message, $channel, $username);
-}
\ No newline at end of file
+}
-- 
1.9.3

