Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
Coordinates | |
100.00% |
11 / 11 |
|
100.00% |
4 / 4 |
8 | |
100.00% |
1 / 1 |
getLatLon | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
zip2LatLon | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
loadData | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 | |||
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace BO\Zmsdldb\Plz; |
4 | |
5 | /** |
6 | * Translate a german zip code into wgs84 coordinates |
7 | */ |
8 | class Coordinates |
9 | { |
10 | /** |
11 | * Store data |
12 | * @var Array $data |
13 | */ |
14 | public $data = array(); |
15 | |
16 | /** |
17 | * @param Int $plz |
18 | */ |
19 | public function getLatLon($plz) |
20 | { |
21 | if (array_key_exists($plz, $this->data)) { |
22 | return $this->data[$plz]; |
23 | } |
24 | return false; |
25 | } |
26 | |
27 | public static function zip2LatLon($plz) |
28 | { |
29 | $coordinates = new self(); |
30 | return $coordinates->getLatLon($plz); |
31 | } |
32 | |
33 | public function loadData($file = null) |
34 | { |
35 | if (null === $file) { |
36 | $file = __DIR__ . DIRECTORY_SEPARATOR . 'plz_geodb.json'; |
37 | } |
38 | if (!is_readable($file) || !is_file($file)) { |
39 | throw new \Exception("Cannot read file $file"); |
40 | } |
41 | $this->data = json_decode(file_get_contents($file), 1); |
42 | } |
43 | |
44 | /** |
45 | * @param String $file (optional) Path to json file with data |
46 | * |
47 | */ |
48 | public function __construct($file = null) |
49 | { |
50 | $this->loadData($file); |
51 | } |
52 | } |