WmsOverlayParser   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0

1 Method

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