Completed
Push — master ( aad1d1...54b5b7 )
by Maciej
12s
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   +33 added lines, -33 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;
@@ -195,11 +195,11 @@  discard block
 block discarded – undo
195 195
 	 *
196 196
 	 * @param string $field
197 197
 	 */
198
-	protected function field_value( $field ) {
198
+	protected function field_value($field) {
199 199
 		$input = $this->utilize('input');
200
-		if( $input->has( $field ) ) {
201
-			$input = $input->get_array( false );
202
-			return $input[ $field ];
200
+		if ($input->has($field)) {
201
+			$input = $input->get_array(false);
202
+			return $input[$field];
203 203
 		}
204 204
 		return null;
205 205
 	}
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param string (optional) $value
216 216
 	 * @return string|null
217 217
 	 */
218
-	protected function string_or_null( $response, $field = null, $value = null ) {
219
-		return ( $this->input( $field )->contains( $field, $value ) ) ? $response : null;
218
+	protected function string_or_null($response, $field = null, $value = null) {
219
+		return ($this->input($field)->contains($field, $value)) ? $response : null;
220 220
 	}
221 221
 
222 222
 	/**
@@ -227,9 +227,9 @@  discard block
 block discarded – undo
227 227
 	 *
228 228
 	 * @param bool $is_valid
229 229
 	 */
230
-	protected function trigger_post_validate_action( $is_valid = false ) {
231
-		$action = ( true === $is_valid ) ? $this->alias : $this->alias .'_fail';
232
-		do_action( $action, $this );
230
+	protected function trigger_post_validate_action($is_valid = false) {
231
+		$action = (true === $is_valid) ? $this->alias : $this->alias.'_fail';
232
+		do_action($action, $this);
233 233
 	}
234 234
 
235 235
 	/**
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
 	 *
241 241
 	 * @param string $component Key indentifier.
242 242
 	 */
243
-	protected function utilize( $component ) {
244
-		return $this->collection[ $component ];
243
+	protected function utilize($component) {
244
+		return $this->collection[$component];
245 245
 	}
246 246
 }
Please login to merge, or discard this patch.