Completed
Pull Request — Gutenberg/master (#757)
by Darren
27:11
created
strategies/validation/EE_Text_Validation_Strategy.strategy.php 2 patches
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -10,52 +10,52 @@
 block discarded – undo
10 10
 class EE_Text_Validation_Strategy extends EE_Validation_Strategy_Base
11 11
 {
12 12
 
13
-    protected $_regex = null;
14
-    /**
15
-     *
16
-     * @param string $validation_error_message
17
-     * @param string $regex a PHP regex; the javascript regex will be derived from this
18
-     */
19
-    public function __construct($validation_error_message = null, $regex = null)
20
-    {
21
-        $this->_regex = $regex;
22
-        parent::__construct($validation_error_message);
23
-    }
13
+	protected $_regex = null;
14
+	/**
15
+	 *
16
+	 * @param string $validation_error_message
17
+	 * @param string $regex a PHP regex; the javascript regex will be derived from this
18
+	 */
19
+	public function __construct($validation_error_message = null, $regex = null)
20
+	{
21
+		$this->_regex = $regex;
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        if ($this->_regex && $normalized_value) {
31
-            if (! preg_match($this->_regex, $normalized_value)) {
32
-                throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
33
-            }
34
-        }
35
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		if ($this->_regex && $normalized_value) {
31
+			if (! preg_match($this->_regex, $normalized_value)) {
32
+				throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
33
+			}
34
+		}
35
+	}
36 36
 
37
-    /**
38
-     * @return array
39
-     */
40
-    public function get_jquery_validation_rule_array()
41
-    {
42
-        if ($this->_regex !== null) {
43
-            return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
44
-        } else {
45
-            return array();
46
-        }
47
-    }
37
+	/**
38
+	 * @return array
39
+	 */
40
+	public function get_jquery_validation_rule_array()
41
+	{
42
+		if ($this->_regex !== null) {
43
+			return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
44
+		} else {
45
+			return array();
46
+		}
47
+	}
48 48
 
49 49
 /**
50 50
  * Translates a PHP regex into a javscript regex (eg, PHP needs separate delimieters, whereas
51 51
  * javscript does not
52 52
  * @return string
53 53
  */
54
-    public function regex_js()
55
-    {
56
-        // first character must be the delimiter
57
-        $delimeter = $this->_regex[0];
58
-        $last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
59
-        return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
60
-    }
54
+	public function regex_js()
55
+	{
56
+		// first character must be the delimiter
57
+		$delimeter = $this->_regex[0];
58
+		$last_occurence_of_delimieter = strrpos($this->_regex, $delimeter);
59
+		return substr($this->_regex, 1, $last_occurence_of_delimieter - 1);
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
     public function validate($normalized_value)
29 29
     {
30 30
         if ($this->_regex && $normalized_value) {
31
-            if (! preg_match($this->_regex, $normalized_value)) {
31
+            if ( ! preg_match($this->_regex, $normalized_value)) {
32 32
                 throw new EE_Validation_Error($this->get_validation_error_message(), 'regex');
33 33
             }
34 34
         }
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
     public function get_jquery_validation_rule_array()
41 41
     {
42 42
         if ($this->_regex !== null) {
43
-            return array( 'regex'=> $this->regex_js(), 'messages' => array( 'regex' => $this->get_validation_error_message() ) );
43
+            return array('regex'=> $this->regex_js(), 'messages' => array('regex' => $this->get_validation_error_message()));
44 44
         } else {
45 45
             return array();
46 46
         }
Please login to merge, or discard this patch.
strategies/validation/EE_Min_Length_Validation_Strategy.strategy.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -11,32 +11,32 @@
 block discarded – undo
11 11
 class EE_Min_Length_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    protected $_min_length;
14
+	protected $_min_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $min_length = 0)
17
-    {
18
-        $this->_min_length = $min_length;
19
-        parent::__construct($validation_error_message);
20
-    }
16
+	public function __construct($validation_error_message = null, $min_length = 0)
17
+	{
18
+		$this->_min_length = $min_length;
19
+		parent::__construct($validation_error_message);
20
+	}
21 21
 
22
-    /**
23
-     * @param $normalized_value
24
-     */
25
-    public function validate($normalized_value)
26
-    {
27
-        if ($this->_min_length > 0 &&
28
-                $normalized_value &&
29
-                is_string($normalized_value) &&
30
-                strlen($normalized_value) < $this->_min_length) {
31
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
32
-        }
33
-    }
22
+	/**
23
+	 * @param $normalized_value
24
+	 */
25
+	public function validate($normalized_value)
26
+	{
27
+		if ($this->_min_length > 0 &&
28
+				$normalized_value &&
29
+				is_string($normalized_value) &&
30
+				strlen($normalized_value) < $this->_min_length) {
31
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'minlength');
32
+		}
33
+	}
34 34
 
35
-    /**
36
-     * @return array
37
-     */
38
-    public function get_jquery_validation_rule_array()
39
-    {
40
-        return array( 'minlength'=> $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
41
-    }
35
+	/**
36
+	 * @return array
37
+	 */
38
+	public function get_jquery_validation_rule_array()
39
+	{
40
+		return array( 'minlength'=> $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,6 +37,6 @@
 block discarded – undo
37 37
      */
38 38
     public function get_jquery_validation_rule_array()
39 39
     {
40
-        return array( 'minlength'=> $this->_min_length, 'messages' => array( 'minlength' => $this->get_validation_error_message() ) );
40
+        return array('minlength'=> $this->_min_length, 'messages' => array('minlength' => $this->get_validation_error_message()));
41 41
     }
42 42
 }
Please login to merge, or discard this patch.
strategies/validation/EE_Simple_HTML_Validation_Strategy.strategy.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -13,57 +13,57 @@
 block discarded – undo
13 13
 class EE_Simple_HTML_Validation_Strategy extends EE_Validation_Strategy_Base
14 14
 {
15 15
 
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $allowedtags = $this->_get_allowed_tags();
23
-            $validation_error_message = sprintf(__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags)));
24
-        }
25
-        parent::__construct($validation_error_message);
26
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$allowedtags = $this->_get_allowed_tags();
23
+			$validation_error_message = sprintf(__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags)));
24
+		}
25
+		parent::__construct($validation_error_message);
26
+	}
27 27
 
28 28
 
29 29
 
30
-    /**
31
-     * get tags allowed
32
-     */
33
-    protected function _get_allowed_tags()
34
-    {
35
-        return EEH_HTML::get_simple_tags();
36
-    }
30
+	/**
31
+	 * get tags allowed
32
+	 */
33
+	protected function _get_allowed_tags()
34
+	{
35
+		return EEH_HTML::get_simple_tags();
36
+	}
37 37
 
38 38
 
39 39
 
40
-    /**
41
-     * add_more_tags
42
-     *
43
-     * generates and returns a string that lists the top-level HTML tags that are allowable for this input
44
-     *
45
-     * @return string
46
-     */
47
-    public function get_list_of_allowed_tags()
48
-    {
49
-        $allowed_tags = $this->_get_allowed_tags();
50
-        ksort($allowed_tags);
51
-        return implode(', ', array_keys($allowed_tags));
52
-    }
40
+	/**
41
+	 * add_more_tags
42
+	 *
43
+	 * generates and returns a string that lists the top-level HTML tags that are allowable for this input
44
+	 *
45
+	 * @return string
46
+	 */
47
+	public function get_list_of_allowed_tags()
48
+	{
49
+		$allowed_tags = $this->_get_allowed_tags();
50
+		ksort($allowed_tags);
51
+		return implode(', ', array_keys($allowed_tags));
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * @param $normalized_value
58
-     * @throws \EE_Validation_Error
59
-     */
60
-    public function validate($normalized_value)
61
-    {
62
-        $allowedtags = $this->_get_allowed_tags();
63
-        parent::validate($normalized_value);
64
-        $normalized_value_sans_tags =  wp_kses("$normalized_value", $allowedtags);
65
-        if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) {
66
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags');
67
-        }
68
-    }
56
+	/**
57
+	 * @param $normalized_value
58
+	 * @throws \EE_Validation_Error
59
+	 */
60
+	public function validate($normalized_value)
61
+	{
62
+		$allowedtags = $this->_get_allowed_tags();
63
+		parent::validate($normalized_value);
64
+		$normalized_value_sans_tags =  wp_kses("$normalized_value", $allowedtags);
65
+		if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) {
66
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags');
67
+		}
68
+	}
69 69
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      */
19 19
     public function __construct($validation_error_message = null)
20 20
     {
21
-        if (! $validation_error_message) {
21
+        if ( ! $validation_error_message) {
22 22
             $allowedtags = $this->_get_allowed_tags();
23 23
             $validation_error_message = sprintf(__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags)));
24 24
         }
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
     {
62 62
         $allowedtags = $this->_get_allowed_tags();
63 63
         parent::validate($normalized_value);
64
-        $normalized_value_sans_tags =  wp_kses("$normalized_value", $allowedtags);
64
+        $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags);
65 65
         if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) {
66 66
             throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags');
67 67
         }
Please login to merge, or discard this patch.
strategies/validation/EE_Plaintext_Validation_Strategy.strategy.php 2 patches
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -13,27 +13,27 @@
 block discarded – undo
13 13
 class EE_Plaintext_Validation_Strategy extends EE_Validation_Strategy_Base
14 14
 {
15 15
 
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $validation_error_message = __("HTML tags are not permitted in this field", "event_espresso");
23
-        }
24
-        parent::__construct($validation_error_message);
25
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$validation_error_message = __("HTML tags are not permitted in this field", "event_espresso");
23
+		}
24
+		parent::__construct($validation_error_message);
25
+	}
26 26
 
27
-    /**
28
-     * @param $normalized_value
29
-     * @throws \EE_Validation_Error
30
-     */
31
-    public function validate($normalized_value)
32
-    {
33
-        $no_tags = wp_strip_all_tags($normalized_value);
34
-        if (strlen($no_tags) < strlen(trim($normalized_value))) {
35
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags');
36
-        }
37
-        parent::validate($normalized_value);
38
-    }
27
+	/**
28
+	 * @param $normalized_value
29
+	 * @throws \EE_Validation_Error
30
+	 */
31
+	public function validate($normalized_value)
32
+	{
33
+		$no_tags = wp_strip_all_tags($normalized_value);
34
+		if (strlen($no_tags) < strlen(trim($normalized_value))) {
35
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags');
36
+		}
37
+		parent::validate($normalized_value);
38
+	}
39 39
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
      */
19 19
     public function __construct($validation_error_message = null)
20 20
     {
21
-        if (! $validation_error_message) {
21
+        if ( ! $validation_error_message) {
22 22
             $validation_error_message = __("HTML tags are not permitted in this field", "event_espresso");
23 23
         }
24 24
         parent::__construct($validation_error_message);
Please login to merge, or discard this patch.
validation/EE_Model_Matching_Query_Validation_Strategy.strategy.php 2 patches
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -13,86 +13,86 @@
 block discarded – undo
13 13
 class EE_Model_Matching_Query_Validation_Strategy extends EE_Validation_Strategy_Base
14 14
 {
15 15
 
16
-    /**
17
-     *
18
-     * @var EEM_Base
19
-     */
20
-    protected $_model;
21
-    protected $_query_params;
22
-    protected $_input_field_name;
16
+	/**
17
+	 *
18
+	 * @var EEM_Base
19
+	 */
20
+	protected $_model;
21
+	protected $_query_params;
22
+	protected $_input_field_name;
23 23
 
24 24
 
25 25
 
26
-    /**
27
-     * @param string $validation_error_message
28
-     * @param string $model_name  name of an EEM_Base model
29
-     * @param array  $query_params     @see EEM_Base::get_all()
30
-     * @param string $input_field_name the input will be treated as this field's value
31
-     * @throws \EE_Error
32
-     */
33
-    public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
34
-    {
35
-        if (! EE_Registry::instance()->is_model_name($model_name)) {
36
-            throw new EE_Error(sprintf(__('You must provide a valid model object ', 'event_espresso'), $model_name));
37
-        }
38
-        $this->_model = EE_Registry::instance()->load_model($model_name);
39
-        $this->_query_params = $query_params;
40
-        if (empty($input_field_name)) {
41
-            $input_field_name = $this->_model->primary_key_name();
42
-        }
43
-        $this->_input_field_name = $input_field_name;
44
-        parent::__construct($validation_error_message);
45
-    }
26
+	/**
27
+	 * @param string $validation_error_message
28
+	 * @param string $model_name  name of an EEM_Base model
29
+	 * @param array  $query_params     @see EEM_Base::get_all()
30
+	 * @param string $input_field_name the input will be treated as this field's value
31
+	 * @throws \EE_Error
32
+	 */
33
+	public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
34
+	{
35
+		if (! EE_Registry::instance()->is_model_name($model_name)) {
36
+			throw new EE_Error(sprintf(__('You must provide a valid model object ', 'event_espresso'), $model_name));
37
+		}
38
+		$this->_model = EE_Registry::instance()->load_model($model_name);
39
+		$this->_query_params = $query_params;
40
+		if (empty($input_field_name)) {
41
+			$input_field_name = $this->_model->primary_key_name();
42
+		}
43
+		$this->_input_field_name = $input_field_name;
44
+		parent::__construct($validation_error_message);
45
+	}
46 46
 
47 47
 
48 48
 
49
-    /**
50
-     * @param $normalized_value
51
-     * @return bool|void
52
-     * @throws \EE_Error
53
-     * @throws \EE_Validation_Error
54
-     */
55
-    public function validate($normalized_value)
56
-    {
57
-        if (empty($normalized_value)) {
58
-            return true;
59
-        }
60
-        $combined_query_params = $this->get_query_params();
61
-        $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
62
-        if (! $this->get_model()->exists($combined_query_params)) {
63
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
64
-        }
65
-    }
49
+	/**
50
+	 * @param $normalized_value
51
+	 * @return bool|void
52
+	 * @throws \EE_Error
53
+	 * @throws \EE_Validation_Error
54
+	 */
55
+	public function validate($normalized_value)
56
+	{
57
+		if (empty($normalized_value)) {
58
+			return true;
59
+		}
60
+		$combined_query_params = $this->get_query_params();
61
+		$combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
62
+		if (! $this->get_model()->exists($combined_query_params)) {
63
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
64
+		}
65
+	}
66 66
 
67
-    /**
68
-     * Gets the model used for querying
69
-     * @return EEM_Base
70
-     */
71
-    public function get_model()
72
-    {
73
-        return $this->_model;
74
-    }
67
+	/**
68
+	 * Gets the model used for querying
69
+	 * @return EEM_Base
70
+	 */
71
+	public function get_model()
72
+	{
73
+		return $this->_model;
74
+	}
75 75
 
76
-    /**
77
-     * Returns query params used for model query
78
-     * @return array
79
-     */
80
-    public function get_query_params()
81
-    {
82
-        return (array) $this->_query_params;
83
-    }
76
+	/**
77
+	 * Returns query params used for model query
78
+	 * @return array
79
+	 */
80
+	public function get_query_params()
81
+	{
82
+		return (array) $this->_query_params;
83
+	}
84 84
 
85
-    /**
86
-     * Gets the name of the field that will be used for lookup.
87
-     * eg it could be "EVT_name", meaning that if there is a model object in
88
-     * the database that has that event name, and matching the other query parameters
89
-     * on this strategy, the input will pass validation server-side
90
-     * @return string
91
-     */
92
-    public function treat_input_as_field()
93
-    {
94
-        return $this->_input_field_name;
95
-    }
85
+	/**
86
+	 * Gets the name of the field that will be used for lookup.
87
+	 * eg it could be "EVT_name", meaning that if there is a model object in
88
+	 * the database that has that event name, and matching the other query parameters
89
+	 * on this strategy, the input will pass validation server-side
90
+	 * @return string
91
+	 */
92
+	public function treat_input_as_field()
93
+	{
94
+		return $this->_input_field_name;
95
+	}
96 96
 }
97 97
 
98 98
 // End of file EE_FUll_HTML_Validation_Strategy.strategy.php
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
      */
33 33
     public function __construct($validation_error_message = null, $model_name = '', $query_params = array(), $input_field_name = '')
34 34
     {
35
-        if (! EE_Registry::instance()->is_model_name($model_name)) {
35
+        if ( ! EE_Registry::instance()->is_model_name($model_name)) {
36 36
             throw new EE_Error(sprintf(__('You must provide a valid model object ', 'event_espresso'), $model_name));
37 37
         }
38 38
         $this->_model = EE_Registry::instance()->load_model($model_name);
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
             return true;
59 59
         }
60 60
         $combined_query_params = $this->get_query_params();
61
-        $combined_query_params[0][ $this->treat_input_as_field() ] = $normalized_value;
62
-        if (! $this->get_model()->exists($combined_query_params)) {
61
+        $combined_query_params[0][$this->treat_input_as_field()] = $normalized_value;
62
+        if ( ! $this->get_model()->exists($combined_query_params)) {
63 63
             throw new EE_Validation_Error($this->get_validation_error_message(), 'no_matching_model_object');
64 64
         }
65 65
     }
Please login to merge, or discard this patch.
strategies/validation/EE_Many_Valued_Validation_Strategy.strategy.php 2 patches
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@
 block discarded – undo
13 13
  */
14 14
 class EE_Many_Valued_Validation_Strategy extends EE_Validation_Strategy_Base
15 15
 {
16
-    protected $_individual_item_validation_strategies = array();
17
-    /**
18
-     *
19
-     * @param EE_Validation_Strategy_Base[] $individual_item_validation_strategies (or a single EE_Validation_Strategy_Base)
20
-     */
21
-    public function __construct($individual_item_validation_strategies)
22
-    {
23
-        if (! is_array($individual_item_validation_strategies)) {
24
-            $individual_item_validation_strategies = array($individual_item_validation_strategies);
25
-        }
26
-        $this->_individual_item_validation_strategies = $individual_item_validation_strategies;
27
-        parent::__construct();
28
-    }
16
+	protected $_individual_item_validation_strategies = array();
17
+	/**
18
+	 *
19
+	 * @param EE_Validation_Strategy_Base[] $individual_item_validation_strategies (or a single EE_Validation_Strategy_Base)
20
+	 */
21
+	public function __construct($individual_item_validation_strategies)
22
+	{
23
+		if (! is_array($individual_item_validation_strategies)) {
24
+			$individual_item_validation_strategies = array($individual_item_validation_strategies);
25
+		}
26
+		$this->_individual_item_validation_strategies = $individual_item_validation_strategies;
27
+		parent::__construct();
28
+	}
29 29
 
30 30
 
31 31
 
32
-    /**
33
-     * Applies all teh individual item validation strategies on each item in the array
34
-     * @param array $normalized_value
35
-     * @return boolean
36
-     */
37
-    public function validate($normalized_value)
38
-    {
39
-        if (is_array($normalized_value)) {
40
-            $items_to_validate = $normalized_value;
41
-        } else {
42
-            $items_to_validate = array($normalized_value);
43
-        }
44
-        foreach ($items_to_validate as $individual_item) {
45
-            foreach ($this->_individual_item_validation_strategies as $validation_strategy) {
46
-                if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
47
-                    $validation_strategy->validate($individual_item);
48
-                }
49
-            }
50
-        }
51
-        return true;
52
-    }
32
+	/**
33
+	 * Applies all teh individual item validation strategies on each item in the array
34
+	 * @param array $normalized_value
35
+	 * @return boolean
36
+	 */
37
+	public function validate($normalized_value)
38
+	{
39
+		if (is_array($normalized_value)) {
40
+			$items_to_validate = $normalized_value;
41
+		} else {
42
+			$items_to_validate = array($normalized_value);
43
+		}
44
+		foreach ($items_to_validate as $individual_item) {
45
+			foreach ($this->_individual_item_validation_strategies as $validation_strategy) {
46
+				if ($validation_strategy instanceof EE_Validation_Strategy_Base) {
47
+					$validation_strategy->validate($individual_item);
48
+				}
49
+			}
50
+		}
51
+		return true;
52
+	}
53 53
 
54 54
 
55 55
 
56
-    /**
57
-     * Extends parent's _construct_finalize so we ALSO set the input
58
-     * on each sub-validation-strategy
59
-     * @param \EE_Form_Input_Base $form_input
60
-     */
61
-    public function _construct_finalize(\EE_Form_Input_Base $form_input)
62
-    {
63
-        parent::_construct_finalize($form_input);
64
-        foreach ($this->_individual_item_validation_strategies as $item_validation_strategy) {
65
-            if ($item_validation_strategy instanceof EE_Validation_Strategy_Base) {
66
-                $item_validation_strategy->_construct_finalize($form_input);
67
-            }
68
-        }
69
-    }
56
+	/**
57
+	 * Extends parent's _construct_finalize so we ALSO set the input
58
+	 * on each sub-validation-strategy
59
+	 * @param \EE_Form_Input_Base $form_input
60
+	 */
61
+	public function _construct_finalize(\EE_Form_Input_Base $form_input)
62
+	{
63
+		parent::_construct_finalize($form_input);
64
+		foreach ($this->_individual_item_validation_strategies as $item_validation_strategy) {
65
+			if ($item_validation_strategy instanceof EE_Validation_Strategy_Base) {
66
+				$item_validation_strategy->_construct_finalize($form_input);
67
+			}
68
+		}
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
      */
21 21
     public function __construct($individual_item_validation_strategies)
22 22
     {
23
-        if (! is_array($individual_item_validation_strategies)) {
23
+        if ( ! is_array($individual_item_validation_strategies)) {
24 24
             $individual_item_validation_strategies = array($individual_item_validation_strategies);
25 25
         }
26 26
         $this->_individual_item_validation_strategies = $individual_item_validation_strategies;
Please login to merge, or discard this patch.
strategies/validation/EE_Max_Length_Validation_Strategy.strategy.php 2 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -11,39 +11,39 @@
 block discarded – undo
11 11
 class EE_Max_Length_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    protected $_max_length;
14
+	protected $_max_length;
15 15
 
16
-    public function __construct($validation_error_message = null, $max_length = EE_INF)
17
-    {
18
-        $this->_max_length = $max_length;
19
-        if ($validation_error_message === null) {
20
-            $validation_error_message = sprintf(__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
-        }
22
-        parent::__construct($validation_error_message);
23
-    }
16
+	public function __construct($validation_error_message = null, $max_length = EE_INF)
17
+	{
18
+		$this->_max_length = $max_length;
19
+		if ($validation_error_message === null) {
20
+			$validation_error_message = sprintf(__('Input is too long. Maximum number of characters is %1$s', 'event_espresso'), $max_length);
21
+		}
22
+		parent::__construct($validation_error_message);
23
+	}
24 24
 
25
-    /**
26
-     * @param $normalized_value
27
-     */
28
-    public function validate($normalized_value)
29
-    {
30
-        if ($this->_max_length !== EE_INF &&
31
-                $normalized_value &&
32
-                is_string($normalized_value) &&
33
-                 strlen($normalized_value) > $this->_max_length) {
34
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
35
-        }
36
-    }
25
+	/**
26
+	 * @param $normalized_value
27
+	 */
28
+	public function validate($normalized_value)
29
+	{
30
+		if ($this->_max_length !== EE_INF &&
31
+				$normalized_value &&
32
+				is_string($normalized_value) &&
33
+				 strlen($normalized_value) > $this->_max_length) {
34
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'maxlength');
35
+		}
36
+	}
37 37
 
38
-    /**
39
-     * @return array
40
-     */
41
-    public function get_jquery_validation_rule_array()
42
-    {
43
-        if ($this->_max_length !== EE_INF) {
44
-            return array( 'maxlength'=> $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
45
-        } else {
46
-            return array();
47
-        }
48
-    }
38
+	/**
39
+	 * @return array
40
+	 */
41
+	public function get_jquery_validation_rule_array()
42
+	{
43
+		if ($this->_max_length !== EE_INF) {
44
+			return array( 'maxlength'=> $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
45
+		} else {
46
+			return array();
47
+		}
48
+	}
49 49
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
     public function get_jquery_validation_rule_array()
42 42
     {
43 43
         if ($this->_max_length !== EE_INF) {
44
-            return array( 'maxlength'=> $this->_max_length, 'messages' => array( 'maxlength' => $this->get_validation_error_message() ) );
44
+            return array('maxlength'=> $this->_max_length, 'messages' => array('maxlength' => $this->get_validation_error_message()));
45 45
         } else {
46 46
             return array();
47 47
         }
Please login to merge, or discard this patch.
strategies/validation/EE_Enum_Validation_Strategy.strategy.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -11,51 +11,51 @@
 block discarded – undo
11 11
 class EE_Enum_Validation_Strategy extends EE_Validation_Strategy_Base
12 12
 {
13 13
 
14
-    /**
15
-     * Check that the value is in the allowed list
16
-     * @param $normalized_value
17
-     * @throws EE_Error
18
-     * @throws EE_Validation_Error
19
-     * @return boolean
20
-     */
21
-    public function validate($normalized_value)
22
-    {
23
-        parent::validate($normalized_value);
24
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
25
-            throw new EE_Error(sprintf(__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso")));
26
-        }
27
-        $enum_options = $this->_input->flat_options();
28
-        if ($normalized_value === true) {
29
-            $normalized_value = 1;
30
-        } elseif ($normalized_value === false) {
31
-            $normalized_value = 0;
32
-        }
33
-        if ($normalized_value !== null && ! array_key_exists($normalized_value, $enum_options)) {
34
-            throw new EE_Validation_Error(
35
-                $this->get_validation_error_message(),
36
-                'invalid_enum_value'
37
-            );
38
-        } else {
39
-            return true;
40
-        }
41
-    }
14
+	/**
15
+	 * Check that the value is in the allowed list
16
+	 * @param $normalized_value
17
+	 * @throws EE_Error
18
+	 * @throws EE_Validation_Error
19
+	 * @return boolean
20
+	 */
21
+	public function validate($normalized_value)
22
+	{
23
+		parent::validate($normalized_value);
24
+		if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
25
+			throw new EE_Error(sprintf(__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso")));
26
+		}
27
+		$enum_options = $this->_input->flat_options();
28
+		if ($normalized_value === true) {
29
+			$normalized_value = 1;
30
+		} elseif ($normalized_value === false) {
31
+			$normalized_value = 0;
32
+		}
33
+		if ($normalized_value !== null && ! array_key_exists($normalized_value, $enum_options)) {
34
+			throw new EE_Validation_Error(
35
+				$this->get_validation_error_message(),
36
+				'invalid_enum_value'
37
+			);
38
+		} else {
39
+			return true;
40
+		}
41
+	}
42 42
 
43
-    /**
44
-     * If we are using the default validation error message, make it dynamic based
45
-     * on the allowed options.
46
-     * @return string
47
-     */
48
-    public function get_validation_error_message()
49
-    {
50
-        $parent_validation_error_message = parent::get_validation_error_message();
51
-        if (! $parent_validation_error_message) {
52
-            $enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : '';
53
-            return sprintf(
54
-                __("This is not allowed option. Allowed options are %s.", "event_espresso"),
55
-                implode(', ', $enum_options)
56
-            );
57
-        } else {
58
-            return $parent_validation_error_message;
59
-        }
60
-    }
43
+	/**
44
+	 * If we are using the default validation error message, make it dynamic based
45
+	 * on the allowed options.
46
+	 * @return string
47
+	 */
48
+	public function get_validation_error_message()
49
+	{
50
+		$parent_validation_error_message = parent::get_validation_error_message();
51
+		if (! $parent_validation_error_message) {
52
+			$enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : '';
53
+			return sprintf(
54
+				__("This is not allowed option. Allowed options are %s.", "event_espresso"),
55
+				implode(', ', $enum_options)
56
+			);
57
+		} else {
58
+			return $parent_validation_error_message;
59
+		}
60
+	}
61 61
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
     public function validate($normalized_value)
22 22
     {
23 23
         parent::validate($normalized_value);
24
-        if (! $this->_input instanceof EE_Form_Input_With_Options_Base) {
24
+        if ( ! $this->_input instanceof EE_Form_Input_With_Options_Base) {
25 25
             throw new EE_Error(sprintf(__("Cannot use Enum Validation Strategy with an input that doesn't have options", "event_espresso")));
26 26
         }
27 27
         $enum_options = $this->_input->flat_options();
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
     public function get_validation_error_message()
49 49
     {
50 50
         $parent_validation_error_message = parent::get_validation_error_message();
51
-        if (! $parent_validation_error_message) {
51
+        if ( ! $parent_validation_error_message) {
52 52
             $enum_options = $this->_input instanceof EE_Form_Input_With_Options_Base ? $this->_input->flat_options() : '';
53 53
             return sprintf(
54 54
                 __("This is not allowed option. Allowed options are %s.", "event_espresso"),
Please login to merge, or discard this patch.
strategies/validation/EE_Credit_Card_Validation_Strategy.strategy.php 2 patches
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -13,55 +13,55 @@
 block discarded – undo
13 13
 class EE_Credit_Card_Validation_Strategy extends EE_Text_Validation_Strategy
14 14
 {
15 15
 
16
-    /**
17
-     * @param null $validation_error_message
18
-     */
19
-    public function __construct($validation_error_message = null)
20
-    {
21
-        if (! $validation_error_message) {
22
-            $validation_error_message = __("Please enter a valid credit card number", "event_espresso");
23
-        }
24
-        parent::__construct($validation_error_message);
25
-    }
16
+	/**
17
+	 * @param null $validation_error_message
18
+	 */
19
+	public function __construct($validation_error_message = null)
20
+	{
21
+		if (! $validation_error_message) {
22
+			$validation_error_message = __("Please enter a valid credit card number", "event_espresso");
23
+		}
24
+		parent::__construct($validation_error_message);
25
+	}
26 26
 
27
-    /**
28
-     * just checks the field isn't blank
29
-     * @param $normalized_value
30
-     * @throws EE_Validation_Error
31
-     * @return void
32
-     */
33
-    public function validate($normalized_value)
34
-    {
35
-        if ($normalized_value && ! $this->verify_is_credit_card($normalized_value)) {
36
-            throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
37
-        }
38
-    }
27
+	/**
28
+	 * just checks the field isn't blank
29
+	 * @param $normalized_value
30
+	 * @throws EE_Validation_Error
31
+	 * @return void
32
+	 */
33
+	public function validate($normalized_value)
34
+	{
35
+		if ($normalized_value && ! $this->verify_is_credit_card($normalized_value)) {
36
+			throw new EE_Validation_Error($this->get_validation_error_message(), 'required');
37
+		}
38
+	}
39 39
 
40 40
 
41 41
 
42
-    /**
43
-     * gets additional validation rules for use in the jQuery validation JS corresponding to this field when displaying.
44
-     *
45
-     * @return array
46
-     */
47
-    public function get_jquery_validation_rule_array()
48
-    {
49
-        return array('creditcard'=>true, 'messages' => array( 'creditcard' => $this->get_validation_error_message() ) );
50
-    }
42
+	/**
43
+	 * gets additional validation rules for use in the jQuery validation JS corresponding to this field when displaying.
44
+	 *
45
+	 * @return array
46
+	 */
47
+	public function get_jquery_validation_rule_array()
48
+	{
49
+		return array('creditcard'=>true, 'messages' => array( 'creditcard' => $this->get_validation_error_message() ) );
50
+	}
51 51
 
52
-    /**
53
-     * Uses regular expressions to verify $card_number is actually a credit card number
54
-     * @param string $card_number
55
-     * @return boolean
56
-     */
57
-    private function verify_is_credit_card($card_number)
58
-    {
59
-        // Credit card: All major cards
60
-        $regex = '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~';
61
-        if (preg_match($regex, $card_number) || empty($card_number)) {
62
-            return true;
63
-        } else {
64
-            return false;
65
-        }
66
-    }
52
+	/**
53
+	 * Uses regular expressions to verify $card_number is actually a credit card number
54
+	 * @param string $card_number
55
+	 * @return boolean
56
+	 */
57
+	private function verify_is_credit_card($card_number)
58
+	{
59
+		// Credit card: All major cards
60
+		$regex = '~^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6011[0-9]{12}|3(?:0[0-5]|[68][0-9])[0-9]{11}|3[47][0-9]{13})$~';
61
+		if (preg_match($regex, $card_number) || empty($card_number)) {
62
+			return true;
63
+		} else {
64
+			return false;
65
+		}
66
+	}
67 67
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
      */
19 19
     public function __construct($validation_error_message = null)
20 20
     {
21
-        if (! $validation_error_message) {
21
+        if ( ! $validation_error_message) {
22 22
             $validation_error_message = __("Please enter a valid credit card number", "event_espresso");
23 23
         }
24 24
         parent::__construct($validation_error_message);
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function get_jquery_validation_rule_array()
48 48
     {
49
-        return array('creditcard'=>true, 'messages' => array( 'creditcard' => $this->get_validation_error_message() ) );
49
+        return array('creditcard'=>true, 'messages' => array('creditcard' => $this->get_validation_error_message()));
50 50
     }
51 51
 
52 52
     /**
Please login to merge, or discard this patch.