Completed
Push — master ( 6773cf...cb49b4 )
by Maciej
15s
created
src/Validator.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;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Collection\MessageCollection;
6 6
 use WFV\Contract\ValidateInterface;
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 	 *
39 39
 	 * @param
40 40
 	 */
41
-	public function __construct( MessageCollection $messages ) {
41
+	public function __construct(MessageCollection $messages) {
42 42
 		$this->messages = $messages;
43 43
 	}
44 44
 
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @return bool
62 62
 	 */
63 63
 	public function is_valid() {
64
-		return empty( $this->errors );
64
+		return empty($this->errors);
65 65
 	}
66 66
 
67 67
 	/**
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
 	 * @param array (optional) $params
77 77
 	 * @return self
78 78
 	 */
79
-	public function validate( ValidateInterface $rule, $field, $value, $optional, $params = false ) {
80
-		$params[] = ( $params ) ? $field : false;
81
-		$valid = $rule->validate( $value, $optional, $params );
82
-		if( !$valid ){
83
-			$this->add_error( $field, $rule->template() );
79
+	public function validate(ValidateInterface $rule, $field, $value, $optional, $params = false) {
80
+		$params[] = ($params) ? $field : false;
81
+		$valid = $rule->validate($value, $optional, $params);
82
+		if (!$valid) {
83
+			$this->add_error($field, $rule->template());
84 84
 		}
85 85
 		return $this;
86 86
 	}
@@ -94,10 +94,10 @@  discard block
 block discarded – undo
94 94
 	 * @param string $field
95 95
 	 * @param array $template
96 96
 	 */
97
-	protected function add_error( $field, array $template ) {
98
-		$message = ( $this->messages->has( $field ) )
99
-			? $this->messages->get_msg( $field, $template['name'] )
97
+	protected function add_error($field, array $template) {
98
+		$message = ($this->messages->has($field))
99
+			? $this->messages->get_msg($field, $template['name'])
100 100
 			: $template['message'];
101
-		$this->errors[ $field ][ $template['name'] ] = $message;
101
+		$this->errors[$field][$template['name']] = $message;
102 102
 	}
103 103
 }
Please login to merge, or discard this patch.
src/Agent/InspectionAgent.php 1 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\Agent;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 
6 6
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
 	 *
27 27
 	 * @param string $action
28 28
 	 */
29
-	public function __construct( $action ) {
29
+	public function __construct($action) {
30 30
 		$this->action = $action;
31 31
 	}
32 32
 
@@ -40,8 +40,8 @@  discard block
 block discarded – undo
40 40
 	 * @return bool
41 41
 	 */
42 42
 	public function safe_submit() {
43
-		if( $this->submit_has_action() ) {
44
-			return ( $_POST['action'] === $this->action ) ? $this->nonce() : false;
43
+		if ($this->submit_has_action()) {
44
+			return ($_POST['action'] === $this->action) ? $this->nonce() : false;
45 45
 		}
46 46
 		return false;
47 47
 	}
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 * @return bool
55 55
 	 */
56 56
 	private function submit_has_action() {
57
-		return isset( $_POST['action'] );
57
+		return isset($_POST['action']);
58 58
 	}
59 59
 
60 60
 	/**
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @return bool
67 67
 	 */
68 68
 	private function nonce() {
69
-		$nonce = $_REQUEST[ $this->action.'_token' ];
70
-		return ( wp_verify_nonce( $nonce, $this->action ) ) ? true : false;
69
+		$nonce = $_REQUEST[$this->action.'_token'];
70
+		return (wp_verify_nonce($nonce, $this->action)) ? true : false;
71 71
 	}
72 72
 
73 73
 }
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' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Agent\InspectionAgent;
6 6
 use WFV\Contract\ArtisanInterface;
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
 	 *
61 61
 	 * @param array $config
62 62
 	 */
63
-	public function __construct( array $config ) {
63
+	public function __construct(array $config) {
64 64
 		$this->config = $config;
65 65
 	}
66 66
 
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
 	 * @param string $action
84 84
 	 * @return WFV\Artisan\FormArtisan
85 85
 	 */
86
-	public function create( $action ) {
87
-		$this->form = new FormComposite( $this, $action );
86
+	public function create($action) {
87
+		$this->form = new FormComposite($this, $action);
88 88
 		return $this;
89 89
 	}
90 90
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 	 * @return WFV\Artisan\FormArtisan
98 98
 	 */
99 99
 	public function errors() {
100
-		$this->collection['errors'] = new ErrorCollection( $this->labels() );
100
+		$this->collection['errors'] = new ErrorCollection($this->labels());
101 101
 		return $this;
102 102
 	}
103 103
 
@@ -110,8 +110,8 @@  discard block
 block discarded – undo
110 110
 	 * @param InspectionAgent $guard
111 111
 	 * @return WFV\Artisan\FormArtisan
112 112
 	 */
113
-	public function input( InspectionAgent $guard ) {
114
-		$this->collection['input'] = new InputCollection( $guard );
113
+	public function input(InspectionAgent $guard) {
114
+		$this->collection['input'] = new InputCollection($guard);
115 115
 		return $this;
116 116
 	}
117 117
 
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function rules() {
127 127
 		$rules = array();
128
-		foreach( $this->config as $field => $options ) {
129
-			$rules[ $field ] = $options['rules'];
128
+		foreach ($this->config as $field => $options) {
129
+			$rules[$field] = $options['rules'];
130 130
 		}
131
-		$this->collection['rules'] = new RuleCollection( $rules );
131
+		$this->collection['rules'] = new RuleCollection($rules);
132 132
 		return $this;
133 133
 	}
134 134
 
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
 	 * @return WFV\Artisan\FormArtisan
142 142
 	 */
143 143
 	public function validator() {
144
-		$this->validator = new Validator( new MessageCollection( $this->config ) );
144
+		$this->validator = new Validator(new MessageCollection($this->config));
145 145
 		return $this;
146 146
 	}
147 147
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
 	 * @return array
156 156
 	 */
157 157
 	protected function labels() {
158
-		return array_map( function( $item ) {
158
+		return array_map(function($item) {
159 159
 			return $item['label'];
160 160
 		}, $this->config);
161 161
 	}
Please login to merge, or discard this patch.
wfv-validate.php 2 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,6 @@
 block discarded – undo
17 17
 
18 18
 require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php';
19 19
 
20
-use WFV\FormComposite;
21 20
 use WFV\Agent\InspectionAgent;
22 21
 use WFV\Artisan\Director;
23 22
 use WFV\Artisan\FormArtisan;
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 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/wfv-validation/blob/master/LICENSE
12 12
 */
13 13
 
14
-define( 'WFV_VALIDATE_VERSION', '0.11.2' );
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.2');
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;
@@ -33,19 +33,19 @@  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
-	$guard = new InspectionAgent( $action );
36
+function wfv_create($action, array &$form, $trim = true) {
37
+	$guard = new InspectionAgent($action);
38 38
 
39
-	$builder = new FormArtisan( $form );
40
-	$form = ( new Director( $action ) )
41
-		->with( 'input', $guard )
42
-		->with( 'rules' )
43
-		->with( 'errors' )
44
-		->with( 'factory' )
45
-		->with( 'validator' )
46
-		->compose( $builder );
39
+	$builder = new FormArtisan($form);
40
+	$form = (new Director($action))
41
+		->with('input', $guard)
42
+		->with('rules')
43
+		->with('errors')
44
+		->with('factory')
45
+		->with('validator')
46
+		->compose($builder);
47 47
 
48
-	if( $form->input()->is_populated() ) {
48
+	if ($form->input()->is_populated()) {
49 49
 		$form->validate();
50 50
 	}
51 51
 }
Please login to merge, or discard this patch.
src/RuleFactory.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' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Rules;
6 6
 
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
 	 * @param string $rule
29 29
 	 * @return ValidateInterface|bool
30 30
 	 */
31
-	public function get( $rule ) {
32
-		if ( !isset( $this->pool[ $rule ] ) ) {
33
-			$class = $this->class_name( $rule );
34
-			$this->pool[ $rule ] = new $class();
31
+	public function get($rule) {
32
+		if (!isset($this->pool[$rule])) {
33
+			$class = $this->class_name($rule);
34
+			$this->pool[$rule] = new $class();
35 35
 		}
36
-		return $this->pool[ $rule ];
36
+		return $this->pool[$rule];
37 37
 	}
38 38
 
39 39
 	/**
@@ -45,8 +45,8 @@  discard block
 block discarded – undo
45 45
 	 * @param string $rule
46 46
 	 * @return string
47 47
 	 */
48
-	protected function class_name( $rule ){
49
-		$name = str_replace(' ', '', ucwords( str_replace('_', ' ', $rule ) ) );
48
+	protected function class_name($rule) {
49
+		$name = str_replace(' ', '', ucwords(str_replace('_', ' ', $rule)));
50 50
 		return 'WFV\Rules\\'.$name;
51 51
 	}
52 52
 }
Please login to merge, or discard this patch.
src/Rules/Boolean.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\Rules;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Rules\AbstractRule;
6 6
 
@@ -32,10 +32,10 @@  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
 		$v = $this->validator->create();
37
-		return ( $optional )
38
-			? $v->optional( $v->create()->boolVal() )->validate( $input )
39
-			: $v->boolVal()->validate( $input );
37
+		return ($optional)
38
+			? $v->optional($v->create()->boolVal())->validate($input)
39
+			: $v->boolVal()->validate($input);
40 40
 	}
41 41
 }
Please login to merge, or discard this patch.
src/Rules/AlphaDash.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\Rules;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Rules\AbstractRule;
6 6
 
@@ -32,10 +32,10 @@  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
 		$v = $this->validator->create();
37
-		return ( $optional )
38
-			? $v->optional( $v->create()->alpha('-_') )->validate( $input )
39
-			: $v->alpha('-_')->validate( $input );
37
+		return ($optional)
38
+			? $v->optional($v->create()->alpha('-_'))->validate($input)
39
+			: $v->alpha('-_')->validate($input);
40 40
 	}
41 41
 }
Please login to merge, or discard this patch.
src/Rules/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\Rules;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Rules\AbstractRule;
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.
src/Rules/AlphaNum.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\Rules;
3
-defined( 'ABSPATH' ) || die();
3
+defined('ABSPATH') || die();
4 4
 
5 5
 use WFV\Rules\AbstractRule;
6 6
 
@@ -32,10 +32,10 @@  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
 		$v = $this->validator->create();
37
-		return ( $optional )
38
-			? $v->optional( $v->create()->alnum() )->validate( $input )
39
-			: $v->alnum()->validate( $input );
37
+		return ($optional)
38
+			? $v->optional($v->create()->alnum())->validate($input)
39
+			: $v->alnum()->validate($input);
40 40
 	}
41 41
 }
Please login to merge, or discard this patch.