Completed
Pull Request — master (#193)
by
unknown
02:22
created

Map_Value_Parser::parse()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 3
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
1
<?php 
2
namespace Carbon_Fields\Updater;
3
4
/**
5
* Class for parsing map input
6
*/
7
class Map_Value_Parser extends Value_Parser {
8
	
9
	/**
10
	 * Prepare $input for map field
11
	 * 
12
	 * @param  array $input 
13
	 * @param  bool $is_option
14
	 * @return array $parsed_data
15
	 */
16
	public static function parse( $input, $is_option ) {
17
		if ( empty( $input ) ) {
18
			return null;
19
		}
20
21
		$expected = array( 'lat', 'lng', 'address', 'zoom' );
22
		$keys     = array_keys( $input );
23
		$diff     = array_diff( $expected, $keys );
24
		$name     = self::$carbon_field->get_name();
0 ignored issues
show
Unused Code introduced by
$name is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
25
26
		if ( ! empty( $diff ) ) {
27
			self::throw_exception( __( 'Please make sure that the update array has the proper structure ( <strong>lat</strong>, <strong>lng</strong>, <strong>address</strong>, <strong>zoom</strong>)', 'crb' ) );
28
		}
29
30
		return $input;
31
	}
32
}