ParameterExtractor   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 0
dl 0
loc 37
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A extract() 0 11 4
A extractFromKeyValueStrings() 0 13 3
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace Maps\Presentation;
6
7
/**
8
 * @licence GNU GPL v2+
9
 * @author Jeroen De Dauw < [email protected] >
10
 */
11
class ParameterExtractor {
12
13
	/**
14
	 * Extracts the value of a parameter from a parameter list.
15
	 *
16
	 * @param string[] $parameterNames Name and aliases of the parameter. First match gets used
17
	 * @param string[] $rawParameters Parameters that did not get processed further than being put in a key-value map
18
	 *
19
	 * @return string|null
20
	 */
21 34
	public function extract( array $parameterNames, array $rawParameters ) {
22 34
		foreach( $parameterNames as $parameterName ) {
23 34
			foreach ( $rawParameters as $rawName => $rawValue ) {
24 25
				if ( trim( strtolower( $rawName ) ) === $parameterName ) {
25 18
					return trim( $rawValue );
26
				}
27
			}
28
		}
29
30 16
		return null;
31
	}
32
33 25
	public static function extractFromKeyValueStrings( array $keyValueStrings ) {
34 25
		$rawParameters = [];
35
36 25
		foreach ( $keyValueStrings as $keyValueString ) {
37 25
			$parts = explode( '=', $keyValueString, 2 );
38
39 25
			if ( count( $parts ) === 2 ) {
40 17
				$rawParameters[$parts[0]] = $parts[1];
41
			}
42
		}
43
44 25
		return $rawParameters;
45
	}
46
47
}
48