Completed
Push — master ( 5af635...fb8d5a )
by Maciej
13s
created
src/Artisan/FormArtisan.php 3 patches
Doc Comments   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	 * @since 0.10.0
81 81
 	 *
82 82
 	 * @param string $action
83
-	 * @return WFV\Artisan\FormArtisan
83
+	 * @return FormArtisan
84 84
 	 */
85 85
 	public function create( $action ) {
86 86
 		$this->form = new FormComposite( $this, $action );
@@ -93,7 +93,7 @@  discard block
 block discarded – undo
93 93
 	 *
94 94
 	 * @since 0.10.0
95 95
 	 *
96
-	 * @return WFV\Artisan\FormArtisan
96
+	 * @return FormArtisan
97 97
 	 */
98 98
 	public function errors() {
99 99
 		$this->collection['errors'] = new ErrorCollection( $this->labels() );
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
 	 * @since 0.10.0
108 108
 	 *
109 109
 	 * @param array $data
110
-	 * @return WFV\Artisan\FormArtisan
110
+	 * @return FormArtisan
111 111
 	 */
112 112
 	public function input( array $data = [] ) {
113 113
 		$input = $data[0];
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 *
122 122
 	 * @since 0.10.0
123 123
 	 *
124
-	 * @return WFV\Artisan\FormArtisan
124
+	 * @return FormArtisan
125 125
 	 */
126 126
 	public function messages() {
127 127
 		$this->collection['messages'] = new MessageCollection( $this->config );
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 *
135 135
 	 * @since 0.10.0
136 136
 	 *
137
-	 * @return WFV\Artisan\FormArtisan
137
+	 * @return FormArtisan
138 138
 	 */
139 139
 	public function rules() {
140 140
 		foreach( $this->config as $field => $options ) {
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 *
151 151
 	 * @since 0.11.0
152 152
 	 *
153
-	 * @return WFV\Artisan\FormArtisan
153
+	 * @return FormArtisan
154 154
 	 */
155 155
 	public function validator() {
156 156
 		$this->validator = new Validator();
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
7 7
 use WFV\Collection\InputCollection;
8 8
 use WFV\Collection\MessageCollection;
9 9
 use WFV\Collection\RuleCollection;
10
-
11 10
 use WFV\FormComposite;
12 11
 use WFV\Validator;
13 12
 
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Artisan;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Contract\ArtisanInterface;
6 6
 use WFV\Collection\ErrorCollection;
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
 	 *
60 60
 	 * @param array $config
61 61
 	 */
62
-	function __construct( array $config ) {
62
+	function __construct(array $config) {
63 63
 		$this->config = $config;
64 64
 	}
65 65
 
@@ -82,8 +82,8 @@  discard block
 block discarded – undo
82 82
 	 * @param string $action
83 83
 	 * @return WFV\Artisan\FormArtisan
84 84
 	 */
85
-	public function create( $action ) {
86
-		$this->form = new FormComposite( $this, $action );
85
+	public function create($action) {
86
+		$this->form = new FormComposite($this, $action);
87 87
 		return $this;
88 88
 	}
89 89
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
 	 * @return WFV\Artisan\FormArtisan
97 97
 	 */
98 98
 	public function errors() {
99
-		$this->collection['errors'] = new ErrorCollection( $this->labels() );
99
+		$this->collection['errors'] = new ErrorCollection($this->labels());
100 100
 		return $this;
101 101
 	}
102 102
 
@@ -109,10 +109,10 @@  discard block
 block discarded – undo
109 109
 	 * @param array $data
110 110
 	 * @return WFV\Artisan\FormArtisan
111 111
 	 */
112
-	public function input( array $data = [] ) {
112
+	public function input(array $data = []) {
113 113
 		$input = $data[0];
114 114
 		$trim = $data[1];
115
-		$this->collection['input'] = new InputCollection( $input, $trim );
115
+		$this->collection['input'] = new InputCollection($input, $trim);
116 116
 		return $this;
117 117
 	}
118 118
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	 * @return WFV\Artisan\FormArtisan
125 125
 	 */
126 126
 	public function messages() {
127
-		$this->collection['messages'] = new MessageCollection( $this->config );
127
+		$this->collection['messages'] = new MessageCollection($this->config);
128 128
 		return $this;
129 129
 	}
130 130
 
@@ -137,10 +137,10 @@  discard block
 block discarded – undo
137 137
 	 * @return WFV\Artisan\FormArtisan
138 138
 	 */
139 139
 	public function rules() {
140
-		foreach( $this->config as $field => $options ) {
141
-			$rules[ $field ] = $options['rules'];
140
+		foreach ($this->config as $field => $options) {
141
+			$rules[$field] = $options['rules'];
142 142
 		}
143
-		$this->collection['rules'] = new RuleCollection( $rules );
143
+		$this->collection['rules'] = new RuleCollection($rules);
144 144
 		return $this;
145 145
 	}
146 146
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
 	 * @return array
168 168
 	 */
169 169
 	protected function labels() {
170
-		return array_map( function( $item ) {
170
+		return array_map(function($item) {
171 171
 			return $item['label'];
172 172
 		}, $this->config);
173 173
 	}
Please login to merge, or discard this patch.
src/Validators/AbstractValidator.php 2 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -110,7 +110,6 @@
 block discarded – undo
110 110
 	 *
111 111
 	 * @since 0.11.0
112 112
 	 *
113
-	 * @param string|array $input
114 113
 	 * @return bool
115 114
 	 */
116 115
 	public function validate( $value ) {
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use \Respect\Validation\Validator as RespectValidator;
6 6
 use \Respect\Validation\Exceptions\NestedValidationException;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 * @since 0.11.0
47 47
 	 *
48 48
 	 */
49
-	abstract protected function set_policy( $optional = false );
49
+	abstract protected function set_policy($optional = false);
50 50
 
51 51
 	/**
52 52
 	 *
@@ -54,11 +54,11 @@  discard block
 block discarded – undo
54 54
 	 * @since 0.11.0
55 55
 	 *
56 56
 	 */
57
-	function __construct( $field ) {
57
+	function __construct($field) {
58 58
 		$this->validator = new RespectValidator();
59 59
 		$this->field = $field;
60 60
 		$args = func_get_args();
61
-		$this->params = ( isset( $args[1] ) ) ? $args[1] : null;
61
+		$this->params = (isset($args[1])) ? $args[1] : null;
62 62
 	}
63 63
 
64 64
 	/**
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @param
92 92
 	 */
93
-	public function set_message( $message ) {
93
+	public function set_message($message) {
94 94
 		$this->template['message'] = $message;
95 95
 	}
96 96
 
@@ -113,8 +113,8 @@  discard block
 block discarded – undo
113 113
 	 * @param string|array $input
114 114
 	 * @return bool
115 115
 	 */
116
-	public function validate( $value ) {
117
-		$is_valid = $this->validator->validate( $value );
116
+	public function validate($value) {
117
+		$is_valid = $this->validator->validate($value);
118 118
 		return $is_valid;
119 119
 	}
120 120
 }
Please login to merge, or discard this patch.
wfv-validate.php 1 patch
Spacing   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-defined( 'ABSPATH' ) or die();
2
+defined('ABSPATH') or die();
3 3
 /*
4 4
 Plugin Name: WFV - Form Validation
5 5
 Plugin URI:  https://macder.github.io/wfv/
@@ -11,12 +11,12 @@  discard block
 block discarded – undo
11 11
 License URI: https://github.com/macder/wp-form-validation/blob/master/LICENSE
12 12
 */
13 13
 
14
-define( 'WFV_VALIDATE_VERSION', '0.11.0' );
15
-define( 'WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7' );
16
-define( 'WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
17
-define( 'WFV_VALIDATE__ACTION_POST', 'validate_form' );
14
+define('WFV_VALIDATE_VERSION', '0.11.0');
15
+define('WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7');
16
+define('WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path(__FILE__));
17
+define('WFV_VALIDATE__ACTION_POST', 'validate_form');
18 18
 
19
-require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php';
19
+require_once WFV_VALIDATE__PLUGIN_DIR.'/vendor/autoload.php';
20 20
 
21 21
 use WFV\FormComposite;
22 22
 use WFV\Agent\InspectionAgent;
@@ -33,21 +33,21 @@  discard block
 block discarded – undo
33 33
  * @param array $form Form arguments
34 34
  * @param bool $trim Trim whitespace from beginning and end of string
35 35
  */
36
-function wfv_create( $action, array &$form, $trim = true ) {
37
-	$inspect = new InspectionAgent( $action );
38
-	$input = ( true === $inspect->safe_submit() ) ? $_POST : array();
36
+function wfv_create($action, array &$form, $trim = true) {
37
+	$inspect = new InspectionAgent($action);
38
+	$input = (true === $inspect->safe_submit()) ? $_POST : array();
39 39
 
40
-	$builder = new FormArtisan( $form );
41
-	$form = ( new Director( $action ) )
42
-		->with( 'input', [ $input, $trim ] )
43
-		->with( 'rules' )
44
-		->with( 'errors' )
45
-		->with( 'messages' )
46
-		->with( 'validator' )
47
-		->compose( $builder );
40
+	$builder = new FormArtisan($form);
41
+	$form = (new Director($action))
42
+		->with('input', [$input, $trim])
43
+		->with('rules')
44
+		->with('errors')
45
+		->with('messages')
46
+		->with('validator')
47
+		->compose($builder);
48 48
 
49
-	if( $input ) {
50
-		wfv_validate( $form );
49
+	if ($input) {
50
+		wfv_validate($form);
51 51
 	}
52 52
 }
53 53
 
@@ -59,21 +59,21 @@  discard block
 block discarded – undo
59 59
  * @param FormComposite $form
60 60
  * @return bool
61 61
  */
62
-function wfv_validate( FormComposite $form ) {
62
+function wfv_validate(FormComposite $form) {
63 63
 	$rules = $form->rules()->get_array();
64 64
 	$messages = $form->messages()->get_array();
65
-	$factory = new ValidatorFactory( $messages );
65
+	$factory = new ValidatorFactory($messages);
66 66
 
67
-	foreach( $rules as $field => $ruleset ) {
67
+	foreach ($rules as $field => $ruleset) {
68 68
 		$optional = in_array('optional', $ruleset);
69
-		if( $optional ) {
70
-			array_shift( $ruleset );
69
+		if ($optional) {
70
+			array_shift($ruleset);
71 71
 		}
72
-		foreach( $ruleset as $rule ) {
73
-			$params = ( is_array( $rule ) ) ? $rule['params'] : null;
74
-			$rule_name = ( is_string( $rule ) ) ? $rule : $rule['rule'];
75
-			$validator = $factory->create( $rule_name, $field, $params, $optional );
76
-			$form->validate( $validator, $field );
72
+		foreach ($ruleset as $rule) {
73
+			$params = (is_array($rule)) ? $rule['params'] : null;
74
+			$rule_name = (is_string($rule)) ? $rule : $rule['rule'];
75
+			$validator = $factory->create($rule_name, $field, $params, $optional);
76
+			$form->validate($validator, $field);
77 77
 		}
78 78
 	}
79 79
 	return $form->is_valid();
Please login to merge, or discard this patch.
src/Collection/MessageCollection.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Collection;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 use WFV\Abstraction\Collectable;
5 5
 /**
6 6
  *
@@ -16,8 +16,8 @@  discard block
 block discarded – undo
16 16
 	 *
17 17
 	 * @param array $form Config array
18 18
 	 */
19
-	function __construct( array $form ) {
20
-		$this->set_messages( $form );
19
+	function __construct(array $form) {
20
+		$this->set_messages($form);
21 21
 	}
22 22
 
23 23
 	/**
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
 	 * @param array $form
42 42
 	 * @return array
43 43
 	 */
44
-	protected function filter_config( array $form ) {
45
-		return array_filter( $form, function( $item ) {
46
-			return array_key_exists('messages', $item );
44
+	protected function filter_config(array $form) {
45
+		return array_filter($form, function($item) {
46
+			return array_key_exists('messages', $item);
47 47
 		});
48 48
 	}
49 49
 
@@ -55,9 +55,9 @@  discard block
 block discarded – undo
55 55
 	 *
56 56
 	 * @param array
57 57
 	 */
58
-	protected function make_array( array $filtered ) {
59
-		foreach( $filtered as $field => $options ) {
60
-			$messages[ $field ] = $options['messages'];
58
+	protected function make_array(array $filtered) {
59
+		foreach ($filtered as $field => $options) {
60
+			$messages[$field] = $options['messages'];
61 61
 		}
62 62
 		return $messages;
63 63
 	}
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
 	 *
71 71
 	 * @param array $form
72 72
 	 */
73
-	protected function set_messages( array $form ) {
74
-		$filtered = $this->filter_config( $form );
75
-		$this->data = $this->make_array( $filtered );
73
+	protected function set_messages(array $form) {
74
+		$filtered = $this->filter_config($form);
75
+		$this->data = $this->make_array($filtered);
76 76
 	}
77 77
 }
Please login to merge, or discard this patch.
src/Validators/Required.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 	 * @since 0.11.0
31 31
 	 *
32 32
 	 */
33
-	public function set_policy( $optional = false ) {
33
+	public function set_policy($optional = false) {
34 34
 		$this->validator->notEmpty();
35 35
 		return $this;
36 36
 	}
Please login to merge, or discard this patch.
src/Validators/Boolean.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
 	 * @since 0.11.0
30 30
 	 *
31 31
 	 */
32
-	public function set_policy( $optional = false ) {
32
+	public function set_policy($optional = false) {
33 33
 		$v = $this->validator;
34
-		$v = ( $optional )
35
-			? $v->optional( $v->create()->boolVal() )
34
+		$v = ($optional)
35
+			? $v->optional($v->create()->boolVal())
36 36
 			: $v->boolVal();
37 37
 		return $this;
38 38
 	}
Please login to merge, or discard this patch.
src/Validators/AlphaDash.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
 	 * @since 0.11.0
30 30
 	 *
31 31
 	 */
32
-	public function set_policy( $optional = false ) {
32
+	public function set_policy($optional = false) {
33 33
 		$v = $this->validator;
34
-		$v = ( $optional )
35
-			? $v->optional( $v->create()->alpha('-_') )
34
+		$v = ($optional)
35
+			? $v->optional($v->create()->alpha('-_'))
36 36
 			: $v->alpha('-_');
37 37
 		return $this;
38 38
 	}
Please login to merge, or discard this patch.
src/Validators/Callback.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -29,11 +29,11 @@  discard block
 block discarded – undo
29 29
 	 * @since 0.11.0
30 30
 	 *
31 31
 	 */
32
-	public function set_policy( $optional = false ) {
32
+	public function set_policy($optional = false) {
33 33
 		$v = $this->validator;
34
-		$v = ( $optional )
35
-			? $v->optional( $v->create()->callback( $this->params[0] ) )
36
-			: $v->callback( $this->params[0] );
34
+		$v = ($optional)
35
+			? $v->optional($v->create()->callback($this->params[0]))
36
+			: $v->callback($this->params[0]);
37 37
 		return $this;
38 38
 	}
39 39
 }
Please login to merge, or discard this patch.
src/Validators/Between.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Validators;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 	 * @since 0.11.0
30 30
 	 *
31 31
 	 */
32
-	public function set_policy( $optional = false ) {
32
+	public function set_policy($optional = false) {
33 33
 		$start = $this->params[0];
34 34
 		$end = $this->params[1];
35 35
 
36 36
 		$v = $this->validator;
37
-		$v = ( $optional )
38
-			? $v->optional( $v->create()->between( $start, $end ) )
39
-			: $v->between( $start, $end );
37
+		$v = ($optional)
38
+			? $v->optional($v->create()->between($start, $end))
39
+			: $v->between($start, $end);
40 40
 		return $this;
41 41
 	}
42 42
 }
Please login to merge, or discard this patch.