From f3b711fd9f7d8e096bf774f9c6cfc0a4ca075919 Mon Sep 17 00:00:00 2001
From: Sai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>
Date: Mon, 28 Dec 2015 15:19:31 -0500
Subject: Refactor: logic to get the rule's error message

---
 system/libraries/Form_validation.php | 73 +++++++++++++++++++++---------------
 1 file changed, 43 insertions(+), 30 deletions(-)

(limited to 'system/libraries/Form_validation.php')

diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c2212585d..12cfdff43 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -637,21 +637,7 @@ class CI_Form_validation {
 				// Set the message type
 				$type = in_array('required', $rules) ? 'required' : 'isset';
 
-				// Check if a custom message is defined
-				if (isset($this->_field_data[$row['field']]['errors'][$type]))
-				{
-					$line = $this->_field_data[$row['field']]['errors'][$type];
-				}
-				elseif (isset($this->_error_messages[$type]))
-				{
-					$line = $this->_error_messages[$type];
-				}
-				elseif (FALSE === ($line = $this->CI->lang->line('form_validation_'.$type))
-					// DEPRECATED support for non-prefixed keys
-					&& FALSE === ($line = $this->CI->lang->line($type, FALSE)))
-				{
-					$line = 'The field was not set';
-				}
+				$line = $this->_get_raw_error_message($type, $row);
 
 				// Build the error message
 				$message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
@@ -820,23 +806,9 @@ class CI_Form_validation {
 				{
 					$line = $this->CI->lang->line('form_validation_error_message_not_set').'(Anonymous function)';
 				}
-				// Check if a custom message is defined
-				elseif (isset($this->_field_data[$row['field']]['errors'][$rule]))
-				{
-					$line = $this->_field_data[$row['field']]['errors'][$rule];
-				}
-				elseif ( ! isset($this->_error_messages[$rule]))
-				{
-					if (FALSE === ($line = $this->CI->lang->line('form_validation_'.$rule))
-						// DEPRECATED support for non-prefixed keys
-						&& FALSE === ($line = $this->CI->lang->line($rule, FALSE)))
-					{
-						$line = $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule.')';
-					}
-				}
 				else
 				{
-					$line = $this->_error_messages[$rule];
+					$line = $this->_get_raw_error_message($rule, $row);
 				}
 
 				// Is the parameter we are inserting into the error message the name
@@ -864,6 +836,47 @@ class CI_Form_validation {
 
 	// --------------------------------------------------------------------
 
+	/**
+	 * Get the error message for the rule
+	 *
+	 * @param string the rule name.
+	 * @param array
+	 * @return string
+	 */
+	private function _get_raw_error_message($key, $row)
+	{
+		$error_message = '';
+		// Check if a custom message is defined through validation config row.
+		if (isset($this->_field_data[$row['field']]['errors'][$key]))
+		{
+			$error_message = $this->_field_data[$row['field']]['errors'][$key];
+		}
+		// check if a custom message has been set using the set_message() function
+		elseif (isset($this->_error_messages[$key]))
+		{
+			$error_message = $this->_error_messages[$key];
+		}
+		// check if we have an error message in lang file
+		elseif (FALSE !== ($line_tmp = $this->CI->lang->line('form_validation_'.$key)))
+		{
+			$error_message = $line_tmp;
+		}
+		// DEPRECATED support for non-prefixed keys, lang file again
+		elseif (FALSE !== ($line_tmp = $this->CI->lang->line($key, FALSE)))
+		{
+			$error_message = $line_tmp;
+		}
+		//error message not found
+		else
+		{
+			$error_message = $this->CI->lang->line('form_validation_error_message_not_set').'('.$key.')';
+		}
+
+		return $error_message;
+	}
+
+	// --------------------------------------------------------------------
+
 	/**
 	 * Translate a field name
 	 *
-- 
cgit v1.2.3-24-g4f1b


From 0951e58f94c970a03f8ac2d5cba31d122bfa948a Mon Sep 17 00:00:00 2001
From: Sai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>
Date: Mon, 28 Dec 2015 15:28:02 -0500
Subject: renamed variable for better readability.

---
 system/libraries/Form_validation.php | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

(limited to 'system/libraries/Form_validation.php')

diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index 12cfdff43..a34694bfe 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -843,33 +843,33 @@ class CI_Form_validation {
 	 * @param array
 	 * @return string
 	 */
-	private function _get_raw_error_message($key, $row)
+	private function _get_raw_error_message($rule_name, $row)
 	{
 		$error_message = '';
-		// Check if a custom message is defined through validation config row.
-		if (isset($this->_field_data[$row['field']]['errors'][$key]))
+		// check if a custom message is defined through validation config row.
+		if (isset($this->_field_data[$row['field']]['errors'][$rule_name]))
 		{
-			$error_message = $this->_field_data[$row['field']]['errors'][$key];
+			$error_message = $this->_field_data[$row['field']]['errors'][$rule_name];
 		}
 		// check if a custom message has been set using the set_message() function
-		elseif (isset($this->_error_messages[$key]))
+		elseif (isset($this->_error_messages[$rule_name]))
 		{
-			$error_message = $this->_error_messages[$key];
+			$error_message = $this->_error_messages[$rule_name];
 		}
 		// check if we have an error message in lang file
-		elseif (FALSE !== ($line_tmp = $this->CI->lang->line('form_validation_'.$key)))
+		elseif (FALSE !== ($line_tmp = $this->CI->lang->line('form_validation_'.$rule_name)))
 		{
 			$error_message = $line_tmp;
 		}
 		// DEPRECATED support for non-prefixed keys, lang file again
-		elseif (FALSE !== ($line_tmp = $this->CI->lang->line($key, FALSE)))
+		elseif (FALSE !== ($line_tmp = $this->CI->lang->line($rule_name, FALSE)))
 		{
 			$error_message = $line_tmp;
 		}
-		//error message not found
+		// error message not found
 		else
 		{
-			$error_message = $this->CI->lang->line('form_validation_error_message_not_set').'('.$key.')';
+			$error_message = $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule_name.')';
 		}
 
 		return $error_message;
-- 
cgit v1.2.3-24-g4f1b


From 0f13e09ebb153315539e1ff7f77698f2709996b5 Mon Sep 17 00:00:00 2001
From: Sai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>
Date: Mon, 28 Dec 2015 15:45:03 -0500
Subject: block comment formatting

---
 system/libraries/Form_validation.php | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

(limited to 'system/libraries/Form_validation.php')

diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index a34694bfe..c37a73418 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -839,9 +839,9 @@ class CI_Form_validation {
 	/**
 	 * Get the error message for the rule
 	 *
-	 * @param string the rule name.
-	 * @param array
-	 * @return string
+	 * @param 	string the rule name.
+	 * @param 	array
+	 * @return 	string
 	 */
 	private function _get_raw_error_message($rule_name, $row)
 	{
-- 
cgit v1.2.3-24-g4f1b


From dd149da93a2064937e490977343d152207b73815 Mon Sep 17 00:00:00 2001
From: Sai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>
Date: Mon, 8 Feb 2016 09:32:24 -0500
Subject: code styling changes as suggested by @narfbg

---
 system/libraries/Form_validation.php | 36 +++++++++++++++---------------------
 1 file changed, 15 insertions(+), 21 deletions(-)

(limited to 'system/libraries/Form_validation.php')

diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index c37a73418..da5ab4e04 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -637,7 +637,7 @@ class CI_Form_validation {
 				// Set the message type
 				$type = in_array('required', $rules) ? 'required' : 'isset';
 
-				$line = $this->_get_raw_error_message($type, $row);
+				$line = $this->_get_error_message($type, $row["field"]);
 
 				// Build the error message
 				$message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
@@ -808,7 +808,7 @@ class CI_Form_validation {
 				}
 				else
 				{
-					$line = $this->_get_raw_error_message($rule, $row);
+					$line = $this->_get_error_message($rule, $row["field"]);
 				}
 
 				// Is the parameter we are inserting into the error message the name
@@ -839,40 +839,34 @@ class CI_Form_validation {
 	/**
 	 * Get the error message for the rule
 	 *
-	 * @param 	string the rule name.
-	 * @param 	array
+	 * @param 	string $rule 	The rule name
+	 * @param 	string $field
+	 *
 	 * @return 	string
 	 */
-	private function _get_raw_error_message($rule_name, $row)
+	protected function _get_error_message($rule, $field)
 	{
-		$error_message = '';
 		// check if a custom message is defined through validation config row.
-		if (isset($this->_field_data[$row['field']]['errors'][$rule_name]))
+		if (isset($this->_field_data[$field]['errors'][$rule]))
 		{
-			$error_message = $this->_field_data[$row['field']]['errors'][$rule_name];
+			return $this->_field_data[$field]['errors'][$rule];
 		}
 		// check if a custom message has been set using the set_message() function
-		elseif (isset($this->_error_messages[$rule_name]))
+		elseif (isset($this->_error_messages[$rule]))
 		{
-			$error_message = $this->_error_messages[$rule_name];
+			return $this->_error_messages[$rule];
 		}
-		// check if we have an error message in lang file
-		elseif (FALSE !== ($line_tmp = $this->CI->lang->line('form_validation_'.$rule_name)))
+		elseif (FALSE !== ($tmp = $this->CI->lang->line('form_validation_' . $rule)))
 		{
-			$error_message = $line_tmp;
+			return $tmp;
 		}
 		// DEPRECATED support for non-prefixed keys, lang file again
-		elseif (FALSE !== ($line_tmp = $this->CI->lang->line($rule_name, FALSE)))
-		{
-			$error_message = $line_tmp;
-		}
-		// error message not found
-		else
+		elseif (FALSE !== ($tmp = $this->CI->lang->line($rule, FALSE)))
 		{
-			$error_message = $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule_name.')';
+			return $tmp;
 		}
 
-		return $error_message;
+		return $this->CI->lang->line('form_validation_error_message_not_set'). '(' . $rule . ')';
 	}
 
 	// --------------------------------------------------------------------
-- 
cgit v1.2.3-24-g4f1b


From 37da3bd78530478b2bb2a23bc2144d50e1589313 Mon Sep 17 00:00:00 2001
From: Sai Phaninder Reddy Jonnala <sai.jonnala@gopassport.com>
Date: Tue, 9 Feb 2016 16:09:57 -0500
Subject: Code formatting changes, again. I am bad at this.

---
 system/libraries/Form_validation.php | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

(limited to 'system/libraries/Form_validation.php')

diff --git a/system/libraries/Form_validation.php b/system/libraries/Form_validation.php
index da5ab4e04..097d7aaba 100644
--- a/system/libraries/Form_validation.php
+++ b/system/libraries/Form_validation.php
@@ -637,7 +637,7 @@ class CI_Form_validation {
 				// Set the message type
 				$type = in_array('required', $rules) ? 'required' : 'isset';
 
-				$line = $this->_get_error_message($type, $row["field"]);
+				$line = $this->_get_error_message($type, $row['field']);
 
 				// Build the error message
 				$message = $this->_build_error_msg($line, $this->_translate_fieldname($row['label']));
@@ -808,7 +808,7 @@ class CI_Form_validation {
 				}
 				else
 				{
-					$line = $this->_get_error_message($rule, $row["field"]);
+					$line = $this->_get_error_message($rule, $row['field']);
 				}
 
 				// Is the parameter we are inserting into the error message the name
@@ -840,8 +840,7 @@ class CI_Form_validation {
 	 * Get the error message for the rule
 	 *
 	 * @param 	string $rule 	The rule name
-	 * @param 	string $field
-	 *
+	 * @param 	string $field	The field name
 	 * @return 	string
 	 */
 	protected function _get_error_message($rule, $field)
@@ -856,7 +855,7 @@ class CI_Form_validation {
 		{
 			return $this->_error_messages[$rule];
 		}
-		elseif (FALSE !== ($tmp = $this->CI->lang->line('form_validation_' . $rule)))
+		elseif (FALSE !== ($tmp = $this->CI->lang->line('form_validation_'.$rule)))
 		{
 			return $tmp;
 		}
@@ -866,7 +865,7 @@ class CI_Form_validation {
 			return $tmp;
 		}
 
-		return $this->CI->lang->line('form_validation_error_message_not_set'). '(' . $rule . ')';
+		return $this->CI->lang->line('form_validation_error_message_not_set').'('.$rule.')';
 	}
 
 	// --------------------------------------------------------------------
-- 
cgit v1.2.3-24-g4f1b