Completed
Push — move ( b63aae...04f5b5 )
by Jeroen De
16:21 queued 06:23
created

WmsOverlayParser::parse()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
cc 4
nc 4
nop 1
1
<?php
2
3
namespace Maps\Presentation\WikitextParsers;
4
5
use Maps\Elements\WmsOverlay;
6
use ValueParsers\ParseException;
7
use ValueParsers\ValueParser;
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 implements ValueParser {
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
	public function parse( $value ) {
30
		if ( !is_string( $value ) ) {
31
			throw new ParseException( 'Not a string' );
32
		}
33
34
		$separator = " ";
35
		$metaData = explode( $separator, $value );
36
37
		if ( count( $metaData ) >= 2 ) {
38
			$wmsOverlay = new WmsOverlay( $metaData[0], $metaData[1] );
39
			if ( count( $metaData ) == 3 ) {
40
				$wmsOverlay->setWmsStyleName( $metaData[2] );
41
			}
42
43
			return $wmsOverlay;
44
		}
45
46
		throw new ParseException( 'Need at least two parameters, url to WMS server and map layer name' );
47
	}
48
49
}
50