Completed
Push — master ( f04bbc...eab9d5 )
by Jeroen De
07:09
created

WmsOverlayParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 9
cts 10
cp 0.9
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A stringParse() 0 15 3
1
<?php
2
3
namespace Maps;
4
5
use Maps\Elements\WmsOverlay;
6
use ValueParsers\ParseException;
7
use ValueParsers\StringValueParser;
8
9
/**
10
 * ValueParser that parses the string representation of a WMS layer
11
 *
12
 * @since 3.0
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class WmsOverlayParser extends StringValueParser {
18
19
	/**
20
	 * Parses the provided string and returns the result.
21
	 *
22
	 * @since 3.0
23
	 *
24
	 * @param string $value
25
	 *
26
	 * @return WmsOverlay
27
	 * @throws ParseException
28
	 */
29 2
	protected function stringParse( $value ) {
30 2
		$separator = " ";
31 2
		$metaData = explode($separator, $value);
32
33 2
		if ( count( $metaData ) >= 2 ) {
34 2
			$wmsOverlay = new WmsOverlay( $metaData[0], $metaData[1] );
35 2
			if ( count( $metaData ) == 3) {
36 1
				$wmsOverlay->setWmsStyleName( $metaData[2] );
37 1
			}
38
39 2
			return $wmsOverlay;
40
		}
41
42
		throw new ParseException( 'Need at least two parameters, url to WMS server and map layer name' );
43
	}
44
}
45