Completed
Push — master ( 200886...a4bdfd )
by Jeroen De
10s
created

ImageOverlayParser   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 31
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A stringParse() 0 14 2
A stringToLatLongValue() 0 4 1
1
<?php
2
3
namespace Maps;
4
5
use DataValues\Geo\Parsers\GeoCoordinateParser;
6
use Maps\Elements\ImageOverlay;
7
use Maps\Elements\WmsOverlay;
8
use ValueParsers\ParseException;
9
use ValueParsers\StringValueParser;
10
11
/**
12
 * @since 3.1
13
 *
14
 * @licence GNU GPL v2+
15
 * @author Jeroen De Dauw < [email protected] >
16
 */
17
class ImageOverlayParser extends StringValueParser {
18
19
	/**
20
	 * @since 3.1
21
	 *
22
	 * @param string $value
23
	 *
24
	 * @return WmsOverlay
25
	 * @throws ParseException
26
	 */
27
	protected function stringParse( $value ) {
28
		$parameters = explode( '~', $value );
29
		$imageParameters = explode( ':', $parameters[0], 3 );
30
31
		if ( count( $imageParameters ) === 3 ) {
32
			$boundsNorthEast = $this->stringToLatLongValue( $imageParameters[0] );
33
			$boundsSouthWest = $this->stringToLatLongValue( $imageParameters[1] );
34
			$imageUrl = \MapsMapper::getFileUrl( $imageParameters[2] );
0 ignored issues
show
Deprecated Code introduced by
The method MapsMapper::getFileUrl() has been deprecated.

This method has been deprecated.

Loading history...
35
36
			return new ImageOverlay( $boundsNorthEast, $boundsSouthWest, $imageUrl );
37
		}
38
39
		throw new ParseException( 'Need 3 parameters for an image overlay' );
40
	}
41
42
	private function stringToLatLongValue( $location ) {
43
		$parser = new GeoCoordinateParser( new \ValueParsers\ParserOptions() );
0 ignored issues
show
Deprecated Code introduced by
The class DataValues\Geo\Parsers\GeoCoordinateParser has been deprecated with message: since 2.0, use the base class instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
44
		return $parser->parse( $location );
45
	}
46
47
}
48