1
|
|
|
<?php |
2
|
|
|
namespace Route4Me; |
3
|
|
|
|
4
|
|
|
use Route4Me\Common; |
5
|
|
|
use Route4Me\Enum\Endpoint; |
6
|
|
|
|
7
|
|
|
class Geocoding extends Common |
8
|
|
|
{ |
9
|
|
|
public $strExportFormat; |
10
|
|
|
public $format; |
11
|
|
|
public $addresses; |
12
|
|
|
public $pk; |
13
|
|
|
public $offset; |
14
|
|
|
public $limit; |
15
|
|
|
public $housenumber; |
16
|
|
|
public $zipcode; |
17
|
|
|
|
18
|
|
|
public static function fromArray(array $params) |
19
|
|
|
{ |
20
|
|
|
$geocoding = new Geocoding(); |
21
|
|
|
|
22
|
|
|
foreach($params as $key => $value) { |
23
|
|
|
if (property_exists($geocoding, $key)) { |
24
|
|
|
$geocoding->{$key} = $value; |
25
|
|
|
} |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
return $geocoding; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
View Code Duplication |
public static function forwardGeocoding($params) |
|
|
|
|
32
|
|
|
{ |
33
|
|
|
$body = array( |
34
|
|
|
'strExportFormat' => isset($params['strExportFormat']) ? $params['strExportFormat']: null, |
35
|
|
|
'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
36
|
|
|
); |
37
|
|
|
|
38
|
|
|
$fgCoding = Route4Me::makeRequst(array( |
39
|
|
|
'url' => Endpoint::GEOCODER, |
40
|
|
|
'method' => 'POST', |
41
|
|
|
'body' => $body, |
42
|
|
|
'HTTPHEADER' => 'Content-Type: multipart/form-data' |
43
|
|
|
)); |
44
|
|
|
|
45
|
|
|
return $fgCoding; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public static function reverseGeocoding($params) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$query = array( |
51
|
|
|
'format' => isset($params['format']) ? $params['format']: null, |
52
|
|
|
'addresses' => isset($params['addresses']) ? $params['addresses'] : null, |
53
|
|
|
'detailed' => isset($params['detailed']) ? $params['detailed'] : null, |
54
|
|
|
); |
55
|
|
|
|
56
|
|
|
$fgcoding = Route4Me::makeRequst(array( |
57
|
|
|
'url' => Endpoint::GEOCODER, |
58
|
|
|
'method' => 'POST', |
59
|
|
|
'query' => $query |
60
|
|
|
)); |
61
|
|
|
|
62
|
|
|
return $fgcoding; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
View Code Duplication |
public static function getStreetData($params) |
|
|
|
|
66
|
|
|
{ |
67
|
|
|
$url_query = Endpoint::STREET_DATA; |
68
|
|
|
|
69
|
|
|
if (isset($params['pk'])) { |
70
|
|
|
$url_query.=$params['pk'].'/'; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if (isset($params['offset'])) { |
74
|
|
|
$url_query.=$params['offset'].'/'; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if (isset($params['limit'])) { |
78
|
|
|
$url_query.=$params['limit'].'/'; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
$query = array(); |
82
|
|
|
|
83
|
|
|
$response = Route4Me::makeUrlRequst($url_query, array( |
84
|
|
|
'method' => 'GET', |
85
|
|
|
'query' => $query |
86
|
|
|
)); |
87
|
|
|
|
88
|
|
|
return $response; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
View Code Duplication |
public static function getZipCode($params) |
|
|
|
|
92
|
|
|
{ |
93
|
|
|
$url_query = Endpoint::STREET_DATA_ZIPCODE; |
94
|
|
|
|
95
|
|
|
if (isset($params['zipcode'])) { |
96
|
|
|
$url_query.=$params['zipcode'].'/'; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if (isset($params['offset'])) { |
100
|
|
|
$url_query.=$params['offset'].'/'; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
if (isset($params['limit'])) { |
104
|
|
|
$url_query.=$params['limit'].'/'; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$query = array(); |
108
|
|
|
|
109
|
|
|
$response = Route4Me::makeUrlRequst($url_query, array( |
110
|
|
|
'method' => 'GET', |
111
|
|
|
'query' => $query |
112
|
|
|
)); |
113
|
|
|
|
114
|
|
|
return $response; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
public static function getService($params) |
118
|
|
|
{ |
119
|
|
|
$url_query = Endpoint::STREET_DATA_SERVICE; |
120
|
|
|
|
121
|
|
|
if (isset($params['zipcode'])) { |
122
|
|
|
$url_query.=$params['zipcode'].'/'; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if (isset($params['housenumber'])) { |
126
|
|
|
$url_query.=$params['housenumber'].'/'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if (isset($params['offset'])) { |
130
|
|
|
$url_query.=$params['offset'].'/'; |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
if (isset($params['limit'])) { |
134
|
|
|
$url_query.=$params['limit'].'/'; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
$query = array(); |
138
|
|
|
|
139
|
|
|
$response = Route4Me::makeUrlRequst($url_query, array( |
140
|
|
|
'method' => 'GET', |
141
|
|
|
'query' => $query |
142
|
|
|
)); |
143
|
|
|
|
144
|
|
|
return $response; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.