Completed
Push — develop ( f818c0...470152 )
by Aristeides
02:26
created

Kirki_Field_Sortable   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 48
rs 10
c 0
b 0
f 0
wmc 7
lcom 3
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A set_type() 0 5 1
A set_sanitize_callback() 0 5 1
B sanitize() 0 16 5
1
<?php
2
/**
3
 * Override field methods
4
 *
5
 * @package     Kirki
6
 * @subpackage  Controls
7
 * @copyright   Copyright (c) 2016, Aristeides Stathopoulos
8
 * @license     http://opensource.org/licenses/https://opensource.org/licenses/MIT
9
 * @since       2.3.2
10
 */
11
12
/**
13
 * Field overrides.
14
 */
15
class Kirki_Field_Sortable extends Kirki_Field {
16
17
	/**
18
	 * Sets the control type.
19
	 *
20
	 * @access protected
21
	 */
22
	protected function set_type() {
23
24
		$this->type = 'kirki-sortable';
25
26
	}
27
28
	/**
29
	 * Sets the $sanitize_callback.
30
	 *
31
	 * @access protected
32
	 */
33
	protected function set_sanitize_callback() {
34
35
		$this->sanitize_callback = array( $this, 'sanitize' );
36
37
	}
38
39
	/**
40
	 * Sanitizes sortable values.
41
	 *
42
	 * @access public
43
	 * @param array $value The checkbox value.
44
	 * @return bool
0 ignored issues
show
Documentation introduced by
Should the return type not be array?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
45
	 */
46
	public function sanitize( $value = array() ) {
47
48
		if ( is_string( $value ) || is_numeric( $value ) ) {
49
			return array(
50
				esc_attr( $value ),
51
			);
52
		}
53
		$sanitized_value = array();
54
		foreach ( $value as $sub_value ) {
55
			if ( isset( $this->choices[ $sub_value ] ) ) {
56
				$sanitized_value[] = esc_attr( $sub_value );
57
			}
58
		}
59
		return $sanitized_value;
60
61
	}
62
}
63