Completed
Push — master ( 5af635...fb8d5a )
by Maciej
13s
created
src/Validators/Email.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
 
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
 	 * @since 0.11.0
32 32
 	 *
33 33
 	 */
34
-	public function set_policy( $optional = false ) {
34
+	public function set_policy($optional = false) {
35 35
 		$v = $this->validator;
36
-		$v = ( $optional )
37
-			? $v->optional( $v->create()->email() )
36
+		$v = ($optional)
37
+			? $v->optional($v->create()->email())
38 38
 			: $v->email();
39 39
 		return $this;
40 40
 	}
Please login to merge, or discard this patch.
src/Validators/Alpha.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/ArrayType.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()->arrayType() )
34
+		$v = ($optional)
35
+			? $v->optional($v->create()->arrayType())
36 36
 			: $v->arrayType();
37 37
 		return $this;
38 38
 	}
Please login to merge, or discard this patch.
src/Factory/ValidatorFactory.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV\Factory;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Factory\AbstractFactory;
6 6
 use WFV\Validators;
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param array $messages Custom error messages
30 30
 	 */
31
-	function __construct( array $messages ) {
31
+	function __construct(array $messages) {
32 32
 		$this->messages = $messages;
33 33
 	}
34 34
 
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 	 * @param bool (optional) $optional
44 44
 	 * @return ValidateInterface
45 45
 	 */
46
-	public function create( $rule, $field, $params, $optional = false ) {
47
-		$class = $this->class_name( $rule );
48
-		$validator = ( new $class( $field, $params ) )->set_policy( $optional );
49
-		if( isset( $this->messages[ $field ][ $rule ] ) ) {
50
-			$validator->set_message( $this->messages[ $field ][ $rule ] );
46
+	public function create($rule, $field, $params, $optional = false) {
47
+		$class = $this->class_name($rule);
48
+		$validator = (new $class($field, $params))->set_policy($optional);
49
+		if (isset($this->messages[$field][$rule])) {
50
+			$validator->set_message($this->messages[$field][$rule]);
51 51
 		}
52 52
 		return $validator;
53 53
 	}
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 * @param string $rule
62 62
 	 * @return string
63 63
 	 */
64
-	protected function class_name( $rule ){
65
-		$name = str_replace(' ', '', ucwords( str_replace('_', ' ', $rule ) ) );
64
+	protected function class_name($rule) {
65
+		$name = str_replace(' ', '', ucwords(str_replace('_', ' ', $rule)));
66 66
 		return 'WFV\Validators\\'.$name;
67 67
 	}
68 68
 }
Please login to merge, or discard this patch.
src/Factory/AbstractFactory.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\Factory;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Contract\ValidateInterface;
6 6
 
@@ -11,5 +11,5 @@  discard block
 block discarded – undo
11 11
  */
12 12
 abstract class AbstractFactory {
13 13
 
14
-	abstract public function create( $rule, $field, $params, $optional = false );
14
+	abstract public function create($rule, $field, $params, $optional = false);
15 15
 }
Please login to merge, or discard this patch.
src/FormComposite.php 1 patch
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Abstraction\Composable;
6 6
 use WFV\Contract\ArtisanInterface;
@@ -30,9 +30,9 @@  discard block
 block discarded – undo
30 30
 	 * @param ArtisanInterface $builder
31 31
 	 * @param string $action
32 32
 	 */
33
-	function __construct( ArtisanInterface $builder, $action ) {
33
+	function __construct(ArtisanInterface $builder, $action) {
34 34
 		$this->alias = $action;
35
-		$this->install( $builder->collection );
35
+		$this->install($builder->collection);
36 36
 		$this->validator = $builder->validator;
37 37
 	}
38 38
 
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @param string $value Value to compare against.
46 46
 	 * @return string|null
47 47
 	 */
48
-	public function checked_if( $field = null, $value = null ) {
49
-		return $this->string_or_null( 'checked', $field, $value );
48
+	public function checked_if($field = null, $value = null) {
49
+		return $this->string_or_null('checked', $field, $value);
50 50
 	}
51 51
 
52 52
 	/**
@@ -60,8 +60,8 @@  discard block
 block discarded – undo
60 60
 	 * @param callable (optional) $callback
61 61
 	 * @return string
62 62
 	 */
63
-	public function display( $field = null, callable $callback = null ) {
64
-		echo $input = $this->utilize('input')->escape( $field );
63
+	public function display($field = null, callable $callback = null) {
64
+		echo $input = $this->utilize('input')->escape($field);
65 65
 		return $input;
66 66
 	}
67 67
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param string $value Value to compare against.
120 120
 	 * @return string|null
121 121
 	 */
122
-	public function selected_if( $field = null, $value = null ) {
123
-		return $this->string_or_null( 'selected', $field, $value );
122
+	public function selected_if($field = null, $value = null) {
123
+		return $this->string_or_null('selected', $field, $value);
124 124
 	}
125 125
 
126 126
 	/**
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
 	 */
133 133
 	public function token_fields() {
134 134
 		// TODO - Move markup into something - perhaps a renderable interface?
135
-		$token_name = $this->alias . '_token';
136
-		echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false );
137
-		echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">';
135
+		$token_name = $this->alias.'_token';
136
+		echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false);
137
+		echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">';
138 138
 	}
139 139
 
140 140
 	/**
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
 	 * @since 0.11.0
144 144
 	 *
145 145
 	 */
146
-	public function validate( ValidateInterface $rule, $field ) {
147
-		$input = $this->field_value( $field );
148
-		$this->validator->validate( $rule, $field, $input );
146
+	public function validate(ValidateInterface $rule, $field) {
147
+		$input = $this->field_value($field);
148
+		$this->validator->validate($rule, $field, $input);
149 149
 	}
150 150
 
151 151
 	/**
@@ -156,11 +156,11 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @param string $field
158 158
 	 */
159
-	protected function field_value( $field ) {
159
+	protected function field_value($field) {
160 160
 		$input = $this->utilize('input');
161
-		if( $input->has( $field ) ) {
162
-			$input = $input->get_array( false );
163
-			return $input[ $field ];
161
+		if ($input->has($field)) {
162
+			$input = $input->get_array(false);
163
+			return $input[$field];
164 164
 		}
165 165
 		return null;
166 166
 	}
@@ -176,10 +176,10 @@  discard block
 block discarded – undo
176 176
 	 */
177 177
 	public function is_valid() {
178 178
 		$is_valid = $this->validator->is_valid();
179
-		if( false === $is_valid ) {
180
-			$this->utilize('errors')->set_errors( $this->validator->errors() );
179
+		if (false === $is_valid) {
180
+			$this->utilize('errors')->set_errors($this->validator->errors());
181 181
 		}
182
-		$this->trigger_post_validate_action( $is_valid );
182
+		$this->trigger_post_validate_action($is_valid);
183 183
 		return $is_valid;
184 184
 	}
185 185
 
@@ -194,8 +194,8 @@  discard block
 block discarded – undo
194 194
 	 * @param string (optional) $value
195 195
 	 * @return string|null
196 196
 	 */
197
-	protected function string_or_null( $response, $field = null, $value = null ) {
198
-		return ( $this->input( $field )->contains( $field, $value ) ) ? $response : null;
197
+	protected function string_or_null($response, $field = null, $value = null) {
198
+		return ($this->input($field)->contains($field, $value)) ? $response : null;
199 199
 	}
200 200
 
201 201
 	/**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 *
207 207
 	 * @param bool $is_valid
208 208
 	 */
209
-	protected function trigger_post_validate_action( $is_valid = false ) {
210
-		$action = ( true === $is_valid ) ? $this->alias : $this->alias .'_fail';
211
-		do_action( $action, $this );
209
+	protected function trigger_post_validate_action($is_valid = false) {
210
+		$action = (true === $is_valid) ? $this->alias : $this->alias.'_fail';
211
+		do_action($action, $this);
212 212
 	}
213 213
 }
Please login to merge, or discard this patch.
src/Artisan/FormArtisan.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\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/Validator.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 namespace WFV;
3
-defined( 'ABSPATH' ) or die();
3
+defined('ABSPATH') or die();
4 4
 
5 5
 use WFV\Contract\ValidateInterface;
6 6
 
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	 * @return bool
41 41
 	 */
42 42
 	public function is_valid() {
43
-		return empty( $this->errors );
43
+		return empty($this->errors);
44 44
 	}
45 45
 
46 46
 	/**
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
 	 * @param ValidateInterface $rule
52 52
 	 * @param string|array $value
53 53
 	 */
54
-	public function validate( ValidateInterface $rule, $field, $value ) {
55
-		$valid = $rule->validate( $value );
56
-		if( !$valid ){
57
-			$this->add_error( $field, $rule->template() );
54
+	public function validate(ValidateInterface $rule, $field, $value) {
55
+		$valid = $rule->validate($value);
56
+		if (!$valid) {
57
+			$this->add_error($field, $rule->template());
58 58
 		}
59 59
 	}
60 60
 
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
 	 * @param string $field
68 68
 	 * @param array $template
69 69
 	 */
70
-	protected function add_error( $field, array $template ) {
71
-		$this->errors[ $field ][ $template['name'] ] = $template['message'];
70
+	protected function add_error($field, array $template) {
71
+		$this->errors[$field][$template['name']] = $template['message'];
72 72
 	}
73 73
 }
Please login to merge, or discard this patch.