Passed
Push — GlobeCoordinateParser ( c9f454...5b34b0 )
by Jeroen De
02:14
created

LatLongPrecisionParser   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 8
dl 0
loc 45
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A parse() 0 16 3
A getParsers() 0 7 2
A getNewParsers() 0 6 1
1
<?php
2
3
namespace DataValues\Geo\PackagePrivate;
4
5
use DataValues\Geo\Parsers\DdCoordinateParser;
6
use DataValues\Geo\Parsers\DmCoordinateParser;
7
use DataValues\Geo\Parsers\DmsCoordinateParser;
8
use DataValues\Geo\Parsers\FloatCoordinateParser;
9
use ValueParsers\ParseException;
10
use ValueParsers\ParserOptions;
11
12
class LatLongPrecisionParser {
13
14
	private $options;
15
	private $parsers;
16
17 119
	public function __construct( ParserOptions $options = null ) {
18 119
		$this->options = $options;
19 119
	}
20
21 119
	public function parse( string $coordinate ): LatLongPrecision {
22 119
		foreach ( $this->getParsers() as $parser ) {
23
			try {
24 119
				$latLongPrecision = $parser->parse( $coordinate );
25 86
			} catch ( ParseException $parseException ) {
0 ignored issues
show
Bug introduced by
The class ValueParsers\ParseException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
26 86
				continue;
27
			}
28
29 117
			return $latLongPrecision;
30
		}
31
32 2
		throw new ParseException(
33 2
			'The format of the coordinate could not be determined.',
34
			$coordinate
35
		);
36
	}
37
38
	/**
39
	 * @return PrecisionParser[]
40
	 */
41 119
	private function getParsers(): iterable {
42 119
		if ( $this->parsers === null ) {
43 119
			$this->parsers = new \CachingIterator( $this->getNewParsers(), \CachingIterator::FULL_CACHE );
44
		}
45
46 119
		return $this->parsers;
47
	}
48
49 119
	private function getNewParsers(): \Generator {
50 119
		yield new PrecisionParser( new FloatCoordinateParser( $this->options ), new FloatPrecisionDetector() );
51 119
		yield new PrecisionParser( new DmsCoordinateParser( $this->options ), new DmsPrecisionDetector() );
52 86
		yield new PrecisionParser( new DmCoordinateParser( $this->options ), new DmPrecisionDetector() );
53 56
		yield new PrecisionParser( new DdCoordinateParser( $this->options ), new FloatPrecisionDetector() );
54 31
	}
55
56
}
57