From 0a1a00b249a52fdf7b39866700ddb08834cfa01b Mon Sep 17 00:00:00 2001
From: Darryl Norris <module@darrylnorris.com>
Date: Wed, 15 Oct 2014 22:33:43 +0000
Subject: [PATCH] Fixing Coding Standars Issue #1789220

---
 commerce_ups.admin.inc  | 46 ++++++++++++++++++++++++----------------------
 commerce_ups.install    |  1 +
 commerce_ups.module     | 37 +++++++++++++++++++++++--------------
 commerce_ups.xml.inc    | 21 ++++++++++++++-------
 tests/commerce_ups.test | 25 ++++++++++++++++++-------
 5 files changed, 80 insertions(+), 50 deletions(-)

diff --git a/commerce_ups.admin.inc b/commerce_ups.admin.inc
index d01841a..84500b4 100644
--- a/commerce_ups.admin.inc
+++ b/commerce_ups.admin.inc
@@ -5,14 +5,16 @@
  * Handles admin settings page for Commerce UPS module.
  */
 
-/* hook_settings_form() */
+/**
+ * Implements hook_settings_form().
+ */
 function commerce_ups_settings_form($form, &$form_state) {
   $ups_link = l(t('UPS.com'), 'https://www.ups.com/upsdeveloperkit', array('attributes' => array('target' => '_blank')));
   $form['api'] = array(
     '#type' => 'fieldset',
     '#title' => t('UPS API credentials'),
     '#collapsible' => TRUE,
-    '#description' => t('In order to obtain shipping rate estimates, you must have an account with UPS. You can apply for UPS API credentials at !ups', array('!ups' => $ups_link)),
+    '#description' => check_plain('In order to obtain shipping rate estimates, you must have an account with UPS. You can apply for UPS API credentials at !ups', array('!ups' => $ups_link)),
   );
 
   $encrypted = variable_get('commerce_ups_encrypt', FALSE);
@@ -51,8 +53,7 @@ function commerce_ups_settings_form($form, &$form_state) {
     ),
   );
   if (commerce_ups_encryption_available()) {
-    $form['api']['encryption']['status']['#markup'] =
-      'Encryption is available and configured properly.';
+    $form['api']['encryption']['status']['#markup'] = 'Encryption is available and configured properly.';
     $form['api']['encryption']['commerce_ups_encrypt'] = array(
       '#type' => 'checkbox',
       '#title' => t('Encrypt UPS credentials (HIGHLY RECOMMENDED)'),
@@ -73,22 +74,22 @@ function commerce_ups_settings_form($form, &$form_state) {
   $form['origin']['commerce_ups_company_name'] = array(
     '#type' => 'textfield',
     '#title' => t('Company Name'),
-    '#default_value' => variable_get('commerce_ups_company_name')
+    '#default_value' => variable_get('commerce_ups_company_name'),
   );
   $form['origin']['commerce_ups_address_line_1'] = array(
     '#type' => 'textfield',
     '#title' => t('Address'),
-    '#default_value' => variable_get('commerce_ups_address_line_1')
+    '#default_value' => variable_get('commerce_ups_address_line_1'),
   );
   $form['origin']['commerce_ups_address_line_2'] = array(
     '#type' => 'textfield',
     '#title' => t('Address (Additional)'),
-    '#default_value' => variable_get('commerce_ups_address_line_2')
+    '#default_value' => variable_get('commerce_ups_address_line_2'),
   );
   $form['origin']['commerce_ups_city'] = array(
     '#type' => 'textfield',
     '#title' => t('City'),
-    '#default_value' => variable_get('commerce_ups_city')
+    '#default_value' => variable_get('commerce_ups_city'),
   );
   $form['origin']['commerce_ups_state'] = array(
     '#type' => 'select',
@@ -147,13 +148,13 @@ function commerce_ups_settings_form($form, &$form_state) {
       'WV' => t('West Virginia'),
       'WI' => t('Wisconsin'),
       'WY' => t('Wyoming'),
-    )
+    ),
   );
   $form['origin']['commerce_ups_postal_code'] = array(
     '#type' => 'textfield',
     '#title' => t('Postal Code'),
     '#size' => 5,
-    '#default_value' => variable_get('commerce_ups_postal_code')
+    '#default_value' => variable_get('commerce_ups_postal_code'),
   );
   $form['origin']['commerce_ups_country_code'] = array(
     '#type' => 'select',
@@ -162,7 +163,7 @@ function commerce_ups_settings_form($form, &$form_state) {
     '#options' => array(
       '' => t('Please Select'),
       'US' => t('United States of America'),
-    )
+    ),
   );
   $form['services'] = array(
     '#type' => 'fieldset',
@@ -176,7 +177,7 @@ function commerce_ups_settings_form($form, &$form_state) {
   $form['services']['commerce_ups_services'] = array(
     '#type' => 'checkboxes',
     '#options' => $array_options,
-    '#default_value' => variable_get('commerce_ups_services', array())
+    '#default_value' => variable_get('commerce_ups_services', array()),
   );
   $form['packaging'] = array(
     '#type' => 'fieldset',
@@ -192,7 +193,7 @@ function commerce_ups_settings_form($form, &$form_state) {
     '#value' => '02',
   );
 
-  // Fields for default package size (inches)
+  // Fields for default package size (inches).
   $form['default_package_size'] = array(
     '#type' => 'fieldset',
     '#title' => t('Package size (inches)'),
@@ -232,9 +233,9 @@ function commerce_ups_settings_form($form, &$form_state) {
       complex logic involving multiple package sizes, weights, and void space can be implemented via
       custom modules.
       <br/><br/>
-      UPS has a ' . l('maximum package size', 'http://www.ups.com/content/us/en/resources/prepare/oversize.html', array('attributes' => array('target' => '_blank'))) . '.',
+      UPS has a ' . t('maximum package size', 'http://www.ups.com/content/us/en/resources/prepare/oversize.html', array('attributes' => array('target' => '_blank'))) . '.',
   );
-  
+
   $form['advanced_options'] = array(
     '#type' => 'fieldset',
     '#title' => t('Advanced settings'),
@@ -245,7 +246,7 @@ function commerce_ups_settings_form($form, &$form_state) {
     '#type' => 'select',
     '#title' => t('Pick-up Schedule'),
     '#options' => _commerce_ups_pickup_types(),
-    '#default_value' => variable_get('commerce_ups_pick_up_schedule')
+    '#default_value' => variable_get('commerce_ups_pick_up_schedule'),
   );
   $form['advanced_options']['commerce_ups_shipto_residential'] = array(
     '#type' => 'checkbox',
@@ -279,7 +280,7 @@ function commerce_ups_settings_form($form, &$form_state) {
   return $form;
 }
 
-/*
+/**
  * Implements hook_form_validate().
  */
 function commerce_ups_settings_form_validate($form, &$form_state) {
@@ -290,11 +291,12 @@ function commerce_ups_settings_form_validate($form, &$form_state) {
   //  Girth = 2*width + 2*height
   //  Length + Girth <= 165 inches
   $dimensions = array($values['commerce_ups_default_package_size_length'],
-                      $values['commerce_ups_default_package_size_width'],
-                      $values['commerce_ups_default_package_size_height']);
+    $values['commerce_ups_default_package_size_width'],
+    $values['commerce_ups_default_package_size_height'],
+  );
   sort($dimensions);
   list($height, $width, $length) = $dimensions;
-  $girth = 2*$width + 2*$height;
+  $girth = 2 * $width + 2 * $height;
   if ($length > 108) {
     form_set_error('commerce_ups_default_package_size_length', t('The greatest dimension of the package size must be 108 inches or less.'));
   }
@@ -329,7 +331,7 @@ function commerce_ups_settings_form_validate($form, &$form_state) {
   */
 }
 
-/*
+/**
  * Implements hook_form_submit().
  */
 function commerce_ups_settings_form_submit($form, &$form_state) {
@@ -389,7 +391,7 @@ function commerce_ups_settings_form_submit($form, &$form_state) {
       variable_set($key, $value);
     }
   }
-  
+
   // If the selected services have changed then rebuild caches.
   if ($services !== $form_state['values']['commerce_ups_services']) {
     commerce_shipping_services_reset();
diff --git a/commerce_ups.install b/commerce_ups.install
index f821bd8..19165b0 100644
--- a/commerce_ups.install
+++ b/commerce_ups.install
@@ -39,3 +39,4 @@ function commerce_ups_uninstall() {
     variable_del($data);
   }
 }
+
diff --git a/commerce_ups.module b/commerce_ups.module
index 0305755..8132fc8 100644
--- a/commerce_ups.module
+++ b/commerce_ups.module
@@ -6,7 +6,9 @@
  */
 
 require 'commerce_ups.xml.inc';
-
+/**
+ * Implements hook_menu().
+ */
 function commerce_ups_menu() {
   $items = array();
 
@@ -49,7 +51,8 @@ function commerce_ups_commerce_shipping_service_info() {
   $selected_services = variable_get('commerce_ups_services', array());
 
   foreach ($selected_services as $id => $val) {
-    if ($val != 0) { // if you find a selected one...
+    // if you find a selected one...
+    if ($val != 0) {
       $service = $available_services[$id];
       $shipping_services[$service['slug']] = array(
         'title' => t($service['title']),
@@ -59,7 +62,7 @@ function commerce_ups_commerce_shipping_service_info() {
         'price_component' => 'shipping',
         'callbacks' => array(
           'rate' => 'commerce_ups_service_rate_order',
-        )
+        ),
       );
     }
   }
@@ -125,7 +128,7 @@ function commerce_ups_commerce_shipping_service_rate_options_alter(&$options, $o
   if (variable_get('commerce_ups_show_logo', FALSE)) {
     $image = drupal_get_path('module', 'commerce_ups') . '/images/ups-logo.png';
     if (file_exists($image)) {
-      foreach ($options as $key => &$option) {
+      foreach ($options as $key => & $option) {
         if (preg_match('/^ups_/', $key)) {
           $option = theme('image', array('path' => $image, 'width' => '16px')) . ' ' . $option;
         }
@@ -138,7 +141,7 @@ function commerce_ups_commerce_shipping_service_rate_options_alter(&$options, $o
  * Convenience function to get UPS codes for their services.
  */
 function _commerce_ups_service_list() {
-  $services =  array(
+  $services = array(
     // Domestic services
     '03' => array('title' => t('UPS Ground'), 'description' => t('Ground Delivery')),
     '01' => array('title' => t('UPS Next Day Air'), 'description' => t('Next Day Air')),
@@ -152,10 +155,11 @@ function _commerce_ups_service_list() {
     '07' => array('title' => t('UPS Worldwide Express'), 'description' => t('Worldwide Express')),
     '08' => array('title' => t('UPS Worldwide Expedited'), 'description' => t('Worldwide Expedited')),
     '54' => array('title' => t('UPS Worldwide Express Plus'), 'description' => t('Worldwide Express Plus')),
-    '65' => array('title' => t('UPS Worldwide Saver'), 'description' => t('Worldwide Saver'))
+    '65' => array('title' => t('UPS Worldwide Saver'), 'description' => t('Worldwide Saver')),
   );
 
   /* Make a unique ID to identify the service by */
+
   foreach ($services as $key => $service) {
     $service['slug'] = str_replace(' ', '_', drupal_strtolower($service['title']));
     $services[$key] = $service;
@@ -183,6 +187,9 @@ function _commerce_ups_packaging_types() {
   );
 }
 
+/**
+ * Types of pickup for UPS.
+ */
 function _commerce_ups_pickup_types() {
   return array(
     '06' => 'One Time Pickup',
@@ -190,11 +197,13 @@ function _commerce_ups_pickup_types() {
     '03' => 'Customer Counter',
     '07' => 'On Call Air',
     '19' => 'Letter Center',
-    '20' => 'Air Service Center'
+    '20' => 'Air Service Center',
   );
 }
 
-
+/**
+ * List of Shipping Service.
+ */
 function commerce_ups_commerce_shipping_service_name($service_code) {
   $service_names = _commerce_ups_service_list();
   return $service_names[$service_code]['slug'];
@@ -208,7 +217,7 @@ function commerce_ups_encrypt($value) {
 }
 
 /**
- * Decrypt all api variables in one function call. 
+ * Decrypt all api variables in one function call.
  */
 function commerce_ups_decrypt_vars($include_password) {
   $user_vars = array();
@@ -251,7 +260,7 @@ function commerce_ups_encryption_available($options = array()) {
   }
   elseif ($check_config) {
     if (!variable_get('aes_key_path', FALSE) || variable_get('aes_key_storage_method', FALSE) != 'File') {
-      $warnings[] = 'AES Encryption is installed but not configured securely. Please go ' . l('configure AES Encryption to use file storage', 'admin/settings/aes') . ' to enable encryption for UPS credentials.';
+      $warnings[] = 'AES Encryption is installed but not configured securely. Please go ' . ('configure AES Encryption to use file storage', 'admin/settings/aes') . ' to enable encryption for UPS credentials.';
     }
   }
 
@@ -272,9 +281,9 @@ function commerce_ups_encryption_available($options = array()) {
       if (empty($errors)) {
         return TRUE;
       }
-  case 'warnings':
-    if (empty($errors) && empty($warnings)) {
-      return TRUE;
-    }
+    case 'warnings':
+      if (empty($errors) && empty($warnings)) {
+        return TRUE;
+      }
   }
 }
diff --git a/commerce_ups.xml.inc b/commerce_ups.xml.inc
index 800a68f..5824919 100644
--- a/commerce_ups.xml.inc
+++ b/commerce_ups.xml.inc
@@ -5,7 +5,7 @@
  * Handles XML-related stuff for Commerce UPS module.
  */
 
-/*
+/**
  * This builds the XML to submit to UPS for rates.
  *
  * Here's a decent sample of what the resulting XML should look like: http://sameers.me/2011/01/21/ups-rate-request-sample/
@@ -27,12 +27,14 @@ function commerce_ups_build_rate_request($order) {
 
   $ups_pickupschedule = variable_get('commerce_ups_pick_up_schedule');
 
-  $weight = commerce_physical_order_weight($order, 'lb');  // this returns $weight['unit'] and $weight['weight']
-  $volume = commerce_physical_order_volume($order, 'in');  // this returns $volume['unit'] and $weight['volume']
-
+  // this returns $weight['unit'] and $weight['weight']
+  $weight = commerce_physical_order_weight($order, 'lb');
+  // this returns $volume['unit'] and $weight['volume']
+  $volume = commerce_physical_order_volume($order, 'in');
   $default_package_volume = variable_get('commerce_ups_default_package_size_length', '0') * variable_get('commerce_ups_default_package_size_width', '0') * variable_get('commerce_ups_default_package_size_height', '0');
 
   /* If there is no default package volume, we cannot calculate the number of packages and there is no reason to send to UPS */
+
   if ($default_package_volume == 0) {
     drupal_set_message(t('There was an error with the UPS configuration.'), 'error', FALSE);
     watchdog('commerce_ups', 'The default measurements for the commerce_ups module is empty or is set to zero. Please set the default package dimensions in the settings page for the commerce_ups module. Without the default measurements this module cannot calculate the number of packages and UPS rates will not be displayed.', array(), WATCHDOG_ALERT);
@@ -40,6 +42,7 @@ function commerce_ups_build_rate_request($order) {
   }
 
   /* If there is no total volume or weight for the order, there is no reason to send the request to UPS */
+
   if ($volume['volume'] == NULL || $weight['weight'] == NULL) {
     return FALSE;
   }
@@ -47,9 +50,11 @@ function commerce_ups_build_rate_request($order) {
   $number_of_packages = ceil($volume['volume'] / $default_package_volume);
 
   /* Pickup Schedule */
+
   $schedule_code = variable_get('commerce_ups_pick_up_schedule');
 
   /* Ship To - Customer Shipping Address */
+
   $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
   // Prepare the shipping address for use in the request.
   if (!empty($order_wrapper->commerce_customer_shipping->commerce_customer_address)) {
@@ -113,10 +118,12 @@ function commerce_ups_build_rate_request($order) {
     $dimensions->addChild('Height', variable_get('commerce_ups_default_package_size_height', '0'));
     $package_weight = $package->addChild('PackageWeight');
     $package_weight->addChild('UnitOfMeasurement')->addChild('Code', 'LBS');
-    /* If the weight is less than 0.1, set it to 0.1. I tried to find some "official" documentation
-     *   for this on the UPS site, but could not. I did find that other ecommerce platforms are 
-     *   using this same logic though, I think it is safe for now. mta
+    /*
+     * If the weight is less than 0.1, set it to 0.1. I tried to find some "official" documentation
+     * for this on the UPS site, but could not. I did find that other ecommerce platforms are
+     * using this same logic though, I think it is safe for now. mta
      */
+
     $package_weight->addChild('Weight', max(array(0.1, $weight['weight'] / $number_of_packages)));
     $package_number++;
   }
diff --git a/tests/commerce_ups.test b/tests/commerce_ups.test
index fcdfeec..2c0cf58 100644
--- a/tests/commerce_ups.test
+++ b/tests/commerce_ups.test
@@ -1,8 +1,13 @@
 <?php
 
 /**
-* Administration tests for my module.
-*/
+ * @file
+ * This will allows me to test the commerce ups module.
+ */
+
+/**
+ * Administration tests for my module.
+ */
 class CommerceUPSAdministrationTestCase extends CommerceBaseTestCase {
   /**
    * Order object.
@@ -32,18 +37,24 @@ class CommerceUPSAdministrationTestCase extends CommerceBaseTestCase {
     $final_permissions = array_unique(array_merge($permissions, array('administer shipping')));
     $user = $this->drupalCreateUser($final_permissions);
     $this->drupalLogin($user);
-    
+
     //$this->site_admin = $this->createSiteAdmin();
   }
 
+/**
+ * Log in as store admin.
+ * $this->drupalLogin($this->site_admin);
+ * Access to the config page for checkout forms
+ */
   public function testCommerceUPSSettingsForm() {
-    // Log in as store admin.
-    //$this->drupalLogin($this->site_admin);
-    // Access to the config page for checkout forms
     $this->drupalGet('admin/commerce/config/shipping/methods/ups/edit');
-    $this->assertResponse(200,'Hit something');
+    $this->assertResponse(200, 'Hit something');
   }
 
+/**
+ * This function will generate a fake credentails in order to use the test
+ * funcionality.
+ */
   public function testCommerceUPSFieldSaves() {
     $form = array(
       'commerce_ups_account_id' => 'test',
-- 
1.9.1

