Completed
Push — master ( 2ab477...5ea630 )
by Maciej
17s
created
src/FormComposite.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,6 @@
 block discarded – undo
3 3
 defined( 'ABSPATH' ) || die();
4 4
 
5 5
 use WFV\Artisan\FormArtisan;
6
-use WFV\Contract\ValidateInterface;
7 6
 use WFV\Factory\ValidatorFactory;
8 7
 
9 8
 /**
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 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' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Artisan\FormArtisan;
6 6
 use WFV\Contract\ValidateInterface;
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param ArtisanInterface $builder
49 49
 	 * @param string $action
50 50
 	 */
51
-	public function __construct( FormArtisan $builder, $action ) {
51
+	public function __construct(FormArtisan $builder, $action) {
52 52
 		$this->alias = $action;
53 53
 		$this->collection = $builder->collection;
54 54
 		$this->validator = $builder->validator;
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 	 * @param string $value Value to compare against.
64 64
 	 * @return string|null
65 65
 	 */
66
-	public function checked_if( $field = null, $value = null ) {
67
-		return $this->string_or_null( 'checked', $field, $value );
66
+	public function checked_if($field = null, $value = null) {
67
+		return $this->string_or_null('checked', $field, $value);
68 68
 	}
69 69
 
70 70
 	/**
@@ -78,8 +78,8 @@  discard block
 block discarded – undo
78 78
 	 * @param callable (optional) $callback
79 79
 	 * @return string
80 80
 	 */
81
-	public function display( $field = null, callable $callback = null ) {
82
-		echo $input = $this->utilize('input')->escape( $field );
81
+	public function display($field = null, callable $callback = null) {
82
+		echo $input = $this->utilize('input')->escape($field);
83 83
 		return $input;
84 84
 	}
85 85
 
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
 	 */
118 118
 	public function is_valid() {
119 119
 		$is_valid = $this->validator->is_valid();
120
-		if( false === $is_valid ) {
121
-			$this->utilize('errors')->set_errors( $this->validator->errors() );
120
+		if (false === $is_valid) {
121
+			$this->utilize('errors')->set_errors($this->validator->errors());
122 122
 		}
123
-		$this->trigger_post_validate_action( $is_valid );
123
+		$this->trigger_post_validate_action($is_valid);
124 124
 		return $is_valid;
125 125
 	}
126 126
 
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 	 * @param string $value Value to compare against.
145 145
 	 * @return string|null
146 146
 	 */
147
-	public function selected_if( $field = null, $value = null ) {
148
-		return $this->string_or_null( 'selected', $field, $value );
147
+	public function selected_if($field = null, $value = null) {
148
+		return $this->string_or_null('selected', $field, $value);
149 149
 	}
150 150
 
151 151
 	/**
@@ -157,9 +157,9 @@  discard block
 block discarded – undo
157 157
 	 */
158 158
 	public function token_fields() {
159 159
 		// TODO - Move markup into something - perhaps a renderable interface?
160
-		$token_name = $this->alias . '_token';
161
-		echo $nonce_field = wp_nonce_field( $this->alias, $token_name, false, false );
162
-		echo $action_field = '<input type="hidden" name="action" value="'. $this->alias .'">';
160
+		$token_name = $this->alias.'_token';
161
+		echo $nonce_field = wp_nonce_field($this->alias, $token_name, false, false);
162
+		echo $action_field = '<input type="hidden" name="action" value="'.$this->alias.'">';
163 163
 	}
164 164
 
165 165
 	/**
@@ -170,17 +170,17 @@  discard block
 block discarded – undo
170 170
 	 * @param ValidatorFactory $factory
171 171
 	 * @return self
172 172
 	 */
173
-	public function validate( ValidatorFactory $factory ) {
173
+	public function validate(ValidatorFactory $factory) {
174 174
 		$rule_collection = $this->utilize('rules');
175
-		$rules = $rule_collection->get_array( true );
175
+		$rules = $rule_collection->get_array(true);
176 176
 
177
-		foreach( $rules as $field => $ruleset ) {
178
-			$input = $this->field_value( $field );
179
-			$optional = $rule_collection->is_optional( $field );
177
+		foreach ($rules as $field => $ruleset) {
178
+			$input = $this->field_value($field);
179
+			$optional = $rule_collection->is_optional($field);
180 180
 
181
-			foreach( $ruleset as $index => $rule ) {
182
-				$params = $rule_collection->get_params( $field, $index );
183
-				$this->validator->validate( $factory->get( $rule ), $field, $input, $optional, $params );
181
+			foreach ($ruleset as $index => $rule) {
182
+				$params = $rule_collection->get_params($field, $index);
183
+				$this->validator->validate($factory->get($rule), $field, $input, $optional, $params);
184 184
 			}
185 185
 		}
186 186
 		return $this;
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
 	 * @param string $field
197 197
 	 * @return string|array|null
198 198
 	 */
199
-	protected function field_value( $field ) {
199
+	protected function field_value($field) {
200 200
 		$input = $this->utilize('input');
201
-		if( $input->has( $field ) ) {
201
+		if ($input->has($field)) {
202 202
 			$input = $input->get_array();
203
-			return $input[ $field ];
203
+			return $input[$field];
204 204
 		}
205 205
 		return null;
206 206
 	}
@@ -216,9 +216,9 @@  discard block
 block discarded – undo
216 216
 	 * @param string (optional) $value
217 217
 	 * @return string|null
218 218
 	 */
219
-	protected function string_or_null( $response, $field = null, $value = null ) {
219
+	protected function string_or_null($response, $field = null, $value = null) {
220 220
 		$input = $this->utilize('input');
221
-		return ( $input->contains( $field, $value ) ) ? $response : null;
221
+		return ($input->contains($field, $value)) ? $response : null;
222 222
 	}
223 223
 
224 224
 	/**
@@ -229,9 +229,9 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @param bool $is_valid
231 231
 	 */
232
-	protected function trigger_post_validate_action( $is_valid = false ) {
233
-		$action = ( true === $is_valid ) ? $this->alias : $this->alias .'_fail';
234
-		do_action( $action, $this );
232
+	protected function trigger_post_validate_action($is_valid = false) {
233
+		$action = (true === $is_valid) ? $this->alias : $this->alias.'_fail';
234
+		do_action($action, $this);
235 235
 	}
236 236
 
237 237
 	/**
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @param string $component Key indentifier.
244 244
 	 */
245
-	protected function utilize( $component ) {
246
-		return $this->collection[ $component ];
245
+	protected function utilize($component) {
246
+		return $this->collection[$component];
247 247
 	}
248 248
 }
Please login to merge, or discard this patch.
src/Collection/InputCollection.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,6 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @since 0.10.0
28 28
 	 *
29
-	 * @param array $data
30 29
 	 * @param bool $trim
31 30
 	 */
32 31
 	public function __construct( InspectionAgent $guard, $trim = true ) {
@@ -67,6 +66,7 @@  discard block
 block discarded – undo
67 66
 	 * @since 0.11.0
68 67
 	 * @access protected
69 68
 	 *
69
+	 * @param boolean $trim
70 70
 	 */
71 71
 	protected function populate( $trim ) {
72 72
 		if( $this->guard->safe_submit() ) {
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\Collection;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Abstraction\Collectable;
6 6
 use WFV\Agent\InspectionAgent;
@@ -29,9 +29,9 @@  discard block
 block discarded – undo
29 29
 	 * @param array $data
30 30
 	 * @param bool $trim
31 31
 	 */
32
-	public function __construct( InspectionAgent $guard, $trim = true ) {
32
+	public function __construct(InspectionAgent $guard, $trim = true) {
33 33
 		$this->guard = $guard;
34
-		$this->populate( $trim );
34
+		$this->populate($trim);
35 35
 	}
36 36
 
37 37
 	/**
@@ -42,8 +42,8 @@  discard block
 block discarded – undo
42 42
 	 * @param bool $neat With or without token and action attributes.
43 43
 	 * @return array
44 44
 	 */
45
-	public function get_array( $neat = true ) {
46
-		return ( $neat ) ? $this->neat_array() : $this->data;
45
+	public function get_array($neat = true) {
46
+		return ($neat) ? $this->neat_array() : $this->data;
47 47
 	}
48 48
 
49 49
 	/**
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	protected function neat_array() {
58 58
 		$input = $this->data;
59
-		unset( $input[ $input['action'] .'_token'] );
60
-		unset( $input['action'] );
59
+		unset($input[$input['action'].'_token']);
60
+		unset($input['action']);
61 61
 		return $input;
62 62
 	}
63 63
 
@@ -68,12 +68,12 @@  discard block
 block discarded – undo
68 68
 	 * @access protected
69 69
 	 *
70 70
 	 */
71
-	protected function populate( $trim ) {
72
-		if( $this->guard->safe_submit() ) {
73
-			$data = $this->transform_array_leafs( $_POST, 'stripslashes' );
71
+	protected function populate($trim) {
72
+		if ($this->guard->safe_submit()) {
73
+			$data = $this->transform_array_leafs($_POST, 'stripslashes');
74 74
 
75
-			$this->data = ( $trim )
76
-				? $this->transform_array_leafs( $data, 'trim' )
75
+			$this->data = ($trim)
76
+				? $this->transform_array_leafs($data, 'trim')
77 77
 				: $data;
78 78
 		}
79 79
 	}
Please login to merge, or discard this patch.
wfv-validate.php 1 patch
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-defined( 'ABSPATH' ) || die();
2
+defined('ABSPATH') || die();
3 3
 /*
4 4
 Plugin Name: WFV - Form Validation
5 5
 Plugin URI:  https://macder.github.io/wfv/
@@ -11,11 +11,11 @@  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__ ) );
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 17
 
18
-require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php';
18
+require_once WFV_VALIDATE__PLUGIN_DIR.'/vendor/autoload.php';
19 19
 
20 20
 use WFV\FormComposite;
21 21
 use WFV\Agent\InspectionAgent;
@@ -32,19 +32,19 @@  discard block
 block discarded – undo
32 32
  * @param array $form Form arguments
33 33
  * @param bool $trim Trim whitespace from beginning and end of string
34 34
  */
35
-function wfv_create( $action, array &$form, $trim = true ) {
36
-	$guard = new InspectionAgent( $action );
35
+function wfv_create($action, array &$form, $trim = true) {
36
+	$guard = new InspectionAgent($action);
37 37
 
38
-	$builder = new FormArtisan( $form );
39
-	$form = ( new Director( $action ) )
40
-		->with( 'input', $guard )
41
-		->with( 'rules' )
42
-		->with( 'errors' )
43
-		->with( 'validator' )
44
-		->compose( $builder );
38
+	$builder = new FormArtisan($form);
39
+	$form = (new Director($action))
40
+		->with('input', $guard)
41
+		->with('rules')
42
+		->with('errors')
43
+		->with('validator')
44
+		->compose($builder);
45 45
 
46
-	if( $form->input()->is_populated() ) {
47
-		wfv_validate( $form );
46
+	if ($form->input()->is_populated()) {
47
+		wfv_validate($form);
48 48
 	}
49 49
 }
50 50
 
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
  * @param FormComposite $form
57 57
  * @return bool
58 58
  */
59
-function wfv_validate( FormComposite $form ) {
60
-	$factory = ( new ValidatorFactory() )
61
-		->add( $form->rules()->unique() );
62
-	return $form->validate( $factory )->is_valid();
59
+function wfv_validate(FormComposite $form) {
60
+	$factory = (new ValidatorFactory())
61
+		->add($form->rules()->unique());
62
+	return $form->validate($factory)->is_valid();
63 63
 }
Please login to merge, or discard this patch.
src/Validators/Same.php 1 patch
Spacing   +3 added lines, -3 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' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Validators\AbstractValidator;
6 6
 
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
 	 * @param bool (optional) $optional
33 33
 	 * @return bool
34 34
 	 */
35
-	public function validate( $input = null, $optional = false ) {
35
+	public function validate($input = null, $optional = false) {
36 36
 		$args = func_get_args();
37 37
 		$params = $args[2];
38 38
 		$other_field = $params[0];
@@ -40,6 +40,6 @@  discard block
 block discarded – undo
40 40
 
41 41
 		$v = $this->validator->create();
42 42
 
43
-		return $v->keyValue( $other_field, 'equals', $field )->validate( $_POST );
43
+		return $v->keyValue($other_field, 'equals', $field)->validate($_POST);
44 44
 	}
45 45
 }
Please login to merge, or discard this patch.