-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update dataset + handle multiple cities and cantons per zipcode (#47)
* Fix UpdateZipcodeDatasetCommand.php * Change methods in order to retrieve list of cities based of a zipcode * New findOnBy method in CantonManager.php * Exit loop when csv file has been found in UpdateZipcodeDatasetCommand * Add Docs for new findOneBy Method * Rename Method * Use "Ortschaftsname" as city name --------- Co-authored-by: Stefan Zweifel <[email protected]>
- Loading branch information
1 parent
f895d8e
commit 9ea3da5
Showing
12 changed files
with
18,052 additions
and
15,660 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Wnx\SwissCantons; | ||
|
||
/** | ||
* @phpstan-type City array{canton: string, city: string, zipcode: int} | ||
*/ | ||
class CitySearch | ||
{ | ||
/** @var City[] */ | ||
protected array $dataset; | ||
|
||
public function __construct() | ||
{ | ||
$this->dataset = $this->loadDataset(); | ||
} | ||
|
||
/** | ||
* Find Data Set for a City by Zipcode. | ||
* | ||
* @return City[] | ||
*/ | ||
public function findByZipcode(int $zipcode): array | ||
{ | ||
return array_values(array_filter($this->dataset, fn (array $city) => $city['zipcode'] === $zipcode)); | ||
} | ||
|
||
/** | ||
* @return City[] | ||
* @throws \JsonException | ||
*/ | ||
private function loadDataset(): array | ||
{ | ||
return json_decode(file_get_contents(__DIR__.'/data/cities.json'), true, 512, JSON_THROW_ON_ERROR); | ||
} | ||
|
||
/** | ||
* @return City[] | ||
*/ | ||
public function getDataSet(): array | ||
{ | ||
return $this->dataset; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.