@@ -1,6 +1,6 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace WFV\Collection; |
| 3 | -defined( 'ABSPATH' ) || die(); |
|
| 3 | +defined('ABSPATH') || die(); |
|
| 4 | 4 | use WFV\Abstraction\Collectable; |
| 5 | 5 | /** |
| 6 | 6 | * |
@@ -16,8 +16,8 @@ discard block |
||
| 16 | 16 | * |
| 17 | 17 | * @param array $form Config array |
| 18 | 18 | */ |
| 19 | - public function __construct( array $form ) { |
|
| 20 | - $this->set_messages( $form ); |
|
| 19 | + public function __construct(array $form) { |
|
| 20 | + $this->set_messages($form); |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -40,9 +40,9 @@ discard block |
||
| 40 | 40 | * @param string $rule |
| 41 | 41 | * @return array|null |
| 42 | 42 | */ |
| 43 | - public function get_msg( $field, $rule ) { |
|
| 44 | - return ( isset( $this->data[ $field ][ $rule ] ) ) |
|
| 45 | - ? $this->data[ $field ][ $rule ] |
|
| 43 | + public function get_msg($field, $rule) { |
|
| 44 | + return (isset($this->data[$field][$rule])) |
|
| 45 | + ? $this->data[$field][$rule] |
|
| 46 | 46 | : null; |
| 47 | 47 | } |
| 48 | 48 | |
@@ -56,9 +56,9 @@ discard block |
||
| 56 | 56 | * @param array $form |
| 57 | 57 | * @return array |
| 58 | 58 | */ |
| 59 | - protected function filter_config( array $form ) { |
|
| 60 | - return array_filter( $form, function( $item ) { |
|
| 61 | - if ( array_key_exists('messages', $item ) ) { |
|
| 59 | + protected function filter_config(array $form) { |
|
| 60 | + return array_filter($form, function($item) { |
|
| 61 | + if (array_key_exists('messages', $item)) { |
|
| 62 | 62 | return !empty($item['messages']); |
| 63 | 63 | } |
| 64 | 64 | }); |
@@ -72,10 +72,10 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @param array |
| 74 | 74 | */ |
| 75 | - protected function make_array( array $filtered ) { |
|
| 75 | + protected function make_array(array $filtered) { |
|
| 76 | 76 | $messages = array(); |
| 77 | - foreach( $filtered as $field => $options ) { |
|
| 78 | - $messages[ $field ] = $options['messages']; |
|
| 77 | + foreach ($filtered as $field => $options) { |
|
| 78 | + $messages[$field] = $options['messages']; |
|
| 79 | 79 | } |
| 80 | 80 | return $messages; |
| 81 | 81 | } |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | * |
| 89 | 89 | * @param array $form |
| 90 | 90 | */ |
| 91 | - protected function set_messages( array $form ) { |
|
| 92 | - $filtered = $this->filter_config( $form ); |
|
| 93 | - $this->data = $this->make_array( $filtered ); |
|
| 91 | + protected function set_messages(array $form) { |
|
| 92 | + $filtered = $this->filter_config($form); |
|
| 93 | + $this->data = $this->make_array($filtered); |
|
| 94 | 94 | } |
| 95 | 95 | } |
@@ -1,5 +1,5 @@ discard block |
||
| 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 |
||
| 11 | 11 | License URI: https://github.com/macder/wfv-validation/blob/master/LICENSE |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | -define( 'WFV_VALIDATE_VERSION', '0.11.4' ); |
|
| 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.4'); |
|
| 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\RuleFactory; |
@@ -33,17 +33,17 @@ discard block |
||
| 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 | - $messages = new MessageCollection( $form ); |
|
| 36 | +function wfv_create($action, array &$form, $trim = true) { |
|
| 37 | + $messages = new MessageCollection($form); |
|
| 38 | 38 | |
| 39 | - $builder = new FormArtisan( $form, $action ); |
|
| 40 | - $form = ( new Director() ) |
|
| 41 | - ->with( 'input' ) |
|
| 42 | - ->with( 'rules' ) |
|
| 43 | - ->with( 'errors' ) |
|
| 44 | - ->compose( $builder ); |
|
| 39 | + $builder = new FormArtisan($form, $action); |
|
| 40 | + $form = (new Director()) |
|
| 41 | + ->with('input') |
|
| 42 | + ->with('rules') |
|
| 43 | + ->with('errors') |
|
| 44 | + ->compose($builder); |
|
| 45 | 45 | |
| 46 | - if( $form->input()->is_populated() ) { |
|
| 47 | - ( new Validator( new RuleFactory(), $messages ) )->validate( $form ); |
|
| 46 | + if ($form->input()->is_populated()) { |
|
| 47 | + (new Validator(new RuleFactory(), $messages))->validate($form); |
|
| 48 | 48 | } |
| 49 | 49 | } |