Skip to content

Commit 293b4d5

Browse files
committed
reduce code duplication
1 parent 2eeacf9 commit 293b4d5

1 file changed

Lines changed: 19 additions & 25 deletions

File tree

app/models/GeoFixer.php

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,7 @@ public function findFiasRegion($region)
5959

6060
$regions = $regions->findAll();
6161

62-
array_map(array($this, 'geoDataHandler'), $regions);
63-
64-
$result = $this->findSimilarWord($region, $this->geo_titles);
65-
66-
return $result ? $this->geo_with_ids[$result] : false;
62+
return $this->getResult($regions, $region);
6763
}
6864

6965
/**
@@ -108,11 +104,7 @@ public function findFiasSettlements($city, $region_code)
108104

109105
$settlements = $settlements->findAll();
110106

111-
array_map(array($this, 'geoDataHandler'), $settlements);
112-
113-
$result = $this->findSimilarWord($city, $this->geo_titles);
114-
115-
return $result ? $this->geo_with_ids[$result] : false;
107+
return $this->getResult($settlements, $city);
116108
}
117109

118110
/**
@@ -134,11 +126,7 @@ public function findKladrSettlements($city, $region_code)
134126

135127
$settlements = $settlements->findAll();
136128

137-
array_map(array($this, 'geoDataHandler'), $settlements);
138-
139-
$result = $this->findSimilarWord($city, $this->geo_titles);
140-
141-
return $result ? $this->geo_with_ids[$result] : false;
129+
return $this->getResult($settlements, $city);
142130
}
143131

144132
/**
@@ -160,11 +148,7 @@ public function findFiasStreets($street, $city_id)
160148

161149
$streets = $streets->findAll();
162150

163-
array_map(array($this, 'geoDataHandler'), $streets);
164-
165-
$result = $this->findSimilarWord($street, $this->geo_titles);
166-
167-
return $result ? $this->geo_with_ids[$result] : false;
151+
return $this->getResult($streets, $street);
168152
}
169153

170154
/**
@@ -194,11 +178,7 @@ public function findKladrStreets($street, $city_code)
194178

195179
$streets = $streets->findAll();
196180

197-
array_map(array($this, 'geoDataHandler'), $streets);
198-
199-
$result = $this->findSimilarWord($street, $this->geo_titles);
200-
201-
return $result ? $this->geo_with_ids[$result] : false;
181+
return $this->getResult($streets, $street);
202182
}
203183

204184
/**
@@ -265,5 +245,19 @@ protected function geoDataHandler($geo_array)
265245
$this->geo_with_ids[$geo_array[$this->title_name]] = $geo_array[$this->code_name];
266246
$this->geo_titles[] = $geo_array[$this->title_name];
267247
}
248+
249+
/**
250+
* @param $geo_array
251+
* @param $word
252+
* @return bool|mixed
253+
*/
254+
protected function getResult($geo_array, $word)
255+
{
256+
array_map(array($this, 'geoDataHandler'), $geo_array);
257+
258+
$result = $this->findSimilarWord($word, $this->geo_titles);
259+
260+
return $result ? $this->geo_with_ids[$result] : false;
261+
}
268262
}
269263

0 commit comments

Comments
 (0)