Code Duplication    Length = 34-35 lines in 5 locations

src/Validators/Equals.php 1 location

@@ 12-46 (lines=35) @@
9
 *
10
 * @since 0.11.0
11
 */
12
class Equals extends AbstractValidator {
13
14
	/**
15
	 *
16
	 *
17
	 * @since 0.11.0
18
	 * @access protected
19
	 * @var array
20
	 */
21
	protected $template = [
22
		'message' => '{label} must equal {value}',
23
		'name' => 'equal',
24
	];
25
26
	/**
27
	 * Validate an input value
28
	 *
29
	 * @since 0.11.0
30
	 *
31
	 * @param string|array (optional) $input
32
	 * @param bool (optional) $optional
33
	 * @return bool
34
	 */
35
	public function validate( $input = null, $optional = false ) {
36
		$args = func_get_args();
37
		$params = $args[2];
38
		$compare_value = $params[0];
39
40
		$v = $this->validator->create();
41
42
		return ( $optional )
43
			? $v->optional( $v->create()->equals( $compare_value ) )->validate( $input )
44
			: $v->equals( $compare_value )->validate( $input );
45
	}
46
}
47

src/Validators/LengthMax.php 1 location

@@ 12-45 (lines=34) @@
9
 *
10
 * @since 0.11.0
11
 */
12
class LengthMax extends AbstractValidator {
13
14
	/**
15
	 *
16
	 *
17
	 * @since 0.11.0
18
	 * @access protected
19
	 * @var array
20
	 */
21
	protected $template = [
22
		'message' => '{label} cannot exceed maximum length of {value}',
23
		'name' => 'length_max',
24
	];
25
26
	/**
27
	 * Validate an input value
28
	 *
29
	 * @since 0.11.0
30
	 *
31
	 * @param string|array (optional) $input
32
	 * @param bool (optional) $optional
33
	 * @return bool
34
	 */
35
	public function validate( $input = null, $optional = false ) {
36
		$args = func_get_args();
37
		$params = $args[2];
38
		$max_value = $params[0];
39
40
		$v = $this->validator->create();
41
		return ( $optional )
42
			? $v->optional( $v->create()->length( null, $max_value ) )->validate( $input )
43
			: $v->length( null, $max_value )->validate( $input );
44
	}
45
}
46

src/Validators/LengthMin.php 1 location

@@ 12-45 (lines=34) @@
9
 *
10
 * @since 0.11.0
11
 */
12
class LengthMin extends AbstractValidator {
13
14
	/**
15
	 *
16
	 *
17
	 * @since 0.11.0
18
	 * @access protected
19
	 * @var array
20
	 */
21
	protected $template = [
22
		'message' => '{label} must exceed minimum length of {value}',
23
		'name' => 'length_min',
24
	];
25
26
	/**
27
	 * Validate an input value
28
	 *
29
	 * @since 0.11.0
30
	 *
31
	 * @param string|array (optional) $input
32
	 * @param bool (optional) $optional
33
	 * @return bool
34
	 */
35
	public function validate( $input = null, $optional = false ) {
36
		$args = func_get_args();
37
		$params = $args[2];
38
		$min_value = $params[0];
39
40
		$v = $this->validator->create();
41
		return ( $optional )
42
			? $v->optional( $v->create()->length( $min_value, null ) )->validate( $input )
43
			: $v->length( $min_value, null )->validate( $input );
44
	}
45
}
46

src/Validators/Max.php 1 location

@@ 12-46 (lines=35) @@
9
 *
10
 * @since 0.11.0
11
 */
12
class Max extends AbstractValidator {
13
14
	/**
15
	 *
16
	 *
17
	 * @since 0.11.0
18
	 * @access protected
19
	 * @var array
20
	 */
21
	protected $template = [
22
		'message' => '{label} must not exceed {value}',
23
		'name' => 'max',
24
	];
25
26
	/**
27
	 * Validate an input value
28
	 *
29
	 * @since 0.11.0
30
	 *
31
	 * @param string|array (optional) $input
32
	 * @param bool (optional) $optional
33
	 * @return bool
34
	 */
35
	public function validate( $input = null, $optional = false ) {
36
		$args = func_get_args();
37
		$params = $args[2];
38
		$max_value = $params[0];
39
40
		$v = $this->validator->create();
41
42
		return ( $optional )
43
			? $v->optional( $v->create()->max( $max_value ) )->validate( $input )
44
			: $v->max( $max_value )->validate( $input );
45
	}
46
}
47

src/Validators/Min.php 1 location

@@ 12-46 (lines=35) @@
9
 *
10
 * @since 0.11.0
11
 */
12
class Min extends AbstractValidator {
13
14
	/**
15
	 *
16
	 *
17
	 * @since 0.11.0
18
	 * @access protected
19
	 * @var array
20
	 */
21
	protected $template = [
22
		'message' => '{label} must exceed {value}',
23
		'name' => 'min',
24
	];
25
26
	/**
27
	 * Validate an input value
28
	 *
29
	 * @since 0.11.0
30
	 *
31
	 * @param string|array (optional) $input
32
	 * @param bool (optional) $optional
33
	 * @return bool
34
	 */
35
	public function validate( $input = null, $optional = false ) {
36
		$args = func_get_args();
37
		$params = $args[2];
38
		$min_value = $params[0];
39
40
		$v = $this->validator->create();
41
42
		return ( $optional )
43
			? $v->optional( $v->create()->min( $min_value ) )->validate( $input )
44
			: $v->min( $min_value )->validate( $input );
45
	}
46
}
47