Completed
Pull Request — master (#146)
by Maciej
02:38
created

wfv-validate.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
defined( 'ABSPATH' ) || die();
3
/*
4
Plugin Name: WFV - Form Validation
5
Plugin URI:  https://macder.github.io/wfv/
6
Description: A simple fluid and concise API to manage user input, validation, feedback, and safe output.
7
Version:     0.11.1
8
Author:      Maciej Derulski
9
Author URI:  https://github.com/macder
10
License:     BSD 3-Clause
11
License URI: https://github.com/macder/wp-form-validation/blob/master/LICENSE
12
*/
13
14
define( 'WFV_VALIDATE_VERSION', '0.11.1' );
15
define( 'WFV_VALIDATE__MINIMUM_WP_VERSION', '3.7' );
16
define( 'WFV_VALIDATE__PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
17
18
require_once WFV_VALIDATE__PLUGIN_DIR . '/vendor/autoload.php';
19
20
use WFV\FormComposite;
21
use WFV\Agent\InspectionAgent;
22
use WFV\Artisan\Director;
23
use WFV\Artisan\FormArtisan;
24
use WFV\Factory\ValidatorFactory;
25
26
/**
27
 *
28
 *
29
 * @since 0.10.0
30
 *
31
 * @param string $action
32
 * @param array $form Form arguments
33
 * @param bool $trim Trim whitespace from beginning and end of string
34
 */
35
function wfv_create( $action, array &$form, $trim = true ) {
0 ignored issues
show
The parameter $trim is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
	$guard = new InspectionAgent( $action );
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 );
45
46
	if( $form->input()->is_populated() ) {
47
		wfv_validate( $form );
48
	}
49
}
50
51
/**
52
 *
53
 *
54
 * @since 0.11.0
55
 *
56
 * @param FormComposite $form
57
 * @return bool
58
 */
59
function wfv_validate( FormComposite $form ) {
60
	$factory = ( new ValidatorFactory() )
61
		->add( $form->rules()->unique() );
62
	return $form->validate( $factory )->is_valid();
63
}
64