Completed
Pull Request — master (#114)
by
unknown
02:50
created

FrmFieldEmail::sanitize_value()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @since 3.0
5
 */
6
class FrmFieldEmail extends FrmFieldType {
7
8
	/**
9
	 * @var string
10
	 * @since 3.0
11
	 */
12
	protected $type = 'email';
13
	protected $display_type = 'text';
14
15
	/**
16
	 * @var bool
17
	 * @since 3.0
18
	 */
19
	protected $holds_email_values = true;
20
21
	protected function field_settings_for_type() {
22
		return array(
23
			'size'           => true,
24
			'clear_on_focus' => true,
25
			'invalid'        => true,
26
		);
27
	}
28
29
	/**
30
	 * Validate the email format
31
	 *
32
	 * @param array $args
33
	 *
34
	 * @return array
35
	 */
36
	public function validate( $args ) {
37
		$errors = array();
38 View Code Duplication
		if ( $args['value'] != '' && ! is_email( $args['value'] ) ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
			$errors[ 'field' . $args['id'] ] = FrmFieldsHelper::get_error_msg( $this->field, 'invalid' );
40
		}
41
42
		return $errors;
43
	}
44
45
	/**
46
	 * @since 4.0
47
	 */
48
	public function sanitize_value( &$value ) {
49
		FrmAppHelper::sanitize_value( 'sanitize_email', $value );
50
	}
51
}
52