Completed
Push — master ( 81538e...c2bf57 )
by Jeroen De
10:06
created

WmsOverlayParser   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 0
loc 33
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
	public function parse( $value ) {
32
		if ( !is_string( $value ) ) {
33
			throw new ParseException( 'Not a string' );
34
		}
35
36
		$separator = " ";
37
		$metaData = explode( $separator, $value );
38
39
		if ( count( $metaData ) >= 2 ) {
40
			$wmsOverlay = new WmsOverlay( $metaData[0], $metaData[1] );
41
			if ( count( $metaData ) == 3 ) {
42
				$wmsOverlay->setWmsStyleName( $metaData[2] );
43
			}
44
45
			return $wmsOverlay;
46
		}
47
48
		throw new ParseException( 'Need at least two parameters, url to WMS server and map layer name' );
49
	}
50
51
}
52