Completed
Pull Request — master (#193)
by
unknown
09:54
created

Map_Value_Parser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 16 3
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
}