Skip to content

Commit

Permalink
fix(Ares): fallback address for json->dalsiUdaje[0]->sidlo[0]->sidlo
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Sep 10, 2024
1 parent 5e8a18a commit 25ebbb0
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 14 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"tests": "vendor/bin/tester -s --colors 1 -s -C tests/src",
"coverage": "vendor/bin/tester --coverage coverage.html --coverage-src src/ --colors 1 -s -C tests/src"
"coverage": "vendor/bin/tester --coverage coverage.html --coverage-src src/ --colors 1 -s -C tests/src",
"qa": "composer stan && composer tests",
"stan": "vendor/bin/phpstan analyse",
"tests": "vendor/bin/tester --colors 1 -s -C tests/src"
},
"suggest": {
"guzzlehttp/guzzle": "As default implementation for PSR-7, PSR-17 and PSR-18 standards."
Expand Down
48 changes: 37 additions & 11 deletions src/Ares/Core/JsonToDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,13 @@ public function transform(stdClass $json): Data
$data->vat_payer = $data->sources[Sources::SER_NO_DPH] === true;
$data->company = Strings::trimNull($json->obchodniJmeno ?? null);

$data->zip = Strings::trimNull(Strings::replaceSpace((string) ($json->sidlo->psc ?? $json->sidlo->pscTxt ?? ''))); // input is int
$data->street = Strings::trimNull($json->sidlo->nazevUlice ?? null);
$data->country = Strings::trimNull($json->sidlo->nazevStatu ?? null);
$data->country_code = Strings::trimNull($json->sidlo->kodStatu ?? null);
$data->city = Strings::trimNull($json->sidlo->nazevObce ?? null);
$data->city_post = Strings::trimNull($json->sidlo->nazevMestskeCastiObvodu ?? null);
$data->city_district = Strings::trimNull($json->sidlo->nazevCastiObce ?? null);
$data->district = Strings::trimNull($json->sidlo->nazevOkresu ?? null);
$data->house_number = Helper::houseNumber((string) ($json->sidlo->cisloDomovni ?? $json->sidlo->cisloDoAdresy ?? ''), (string) ($json->sidlo->cisloOrientacni ?? ''), $json->sidlo->cisloOrientacniPismeno ?? '');

if ($data->zip === null && $data->street === null && $data->house_number === null && $data->city === null && isset($json->sidlo->textovaAdresa)) {
$addressExists = isset($json->sidlo) && self::updateAddress($data, $json->sidlo);

if ($addressExists === false && isset($json->dalsiUdaje[0]->sidlo[0]->sidlo)) {
$addressExists = self::updateAddress($data, $json->dalsiUdaje[0]->sidlo[0]->sidlo);
}

if ($addressExists === false && isset($json->sidlo->textovaAdresa)) {
[
'zip' => $data->zip,
'street' => $data->street,
Expand All @@ -56,4 +52,34 @@ public function transform(stdClass $json): Data
return $data;
}


private static function updateAddress(Data $data, stdClass $sidlo): bool
{
$data->zip = Strings::trimNull(Strings::replaceSpace((string) ($sidlo->psc ?? $sidlo->pscTxt ?? ''))); // input is int
$data->street = Strings::trimNull($sidlo->nazevUlice ?? null);
$data->country = Strings::trimNull($sidlo->nazevStatu ?? null);
$data->country_code = Strings::trimNull($sidlo->kodStatu ?? null);
$data->city = Strings::trimNull($sidlo->nazevObce ?? null);
$data->city_post = Strings::trimNull($sidlo->nazevMestskeCastiObvodu ?? null);
$data->city_district = Strings::trimNull($sidlo->nazevCastiObce ?? null);
$data->district = Strings::trimNull($sidlo->nazevOkresu ?? null);
$data->house_number = Helper::houseNumber((string) ($sidlo->cisloDomovni ?? $sidlo->cisloDoAdresy ?? ''), (string) ($sidlo->cisloOrientacni ?? ''), $sidlo->cisloOrientacniPismeno ?? '');

return self::isAddressFilled($data);
}


private static function isAddressFilled(Data $data): bool
{
return $data->zip !== null
|| $data->street !== null
|| $data->country !== null
|| $data->country_code !== null
|| $data->city !== null
|| $data->city_post !== null
|| $data->city_district !== null
|| $data->district !== null
|| $data->house_number !== null;
}

}
39 changes: 39 additions & 0 deletions tests/fixtures/ares/26577321.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"active": true,
"city": "Teplice",
"company": "Sportovní klub PRO SPORT Teplice spolek",
"created": "2008-11-25T00:00:00+01:00",
"dissolved": null,
"city_district": "Teplice",
"city_post": null,
"in": "26577321",
"is_person": false,
"legal_form_code": 706,
"house_number": "2959",
"street": "U Panoramy",
"district": "Teplice",
"tin": null,
"vat_payer": false,
"zip": "41501",
"country": "Česká republika",
"country_code": "CZ",
"nace": [
"93120"
],
"sources": {
"stavZdrojeVr": true,
"stavZdrojeRes": true,
"stavZdrojeRzp": "NEEXISTUJICI",
"stavZdrojeNrpzs": "NEEXISTUJICI",
"stavZdrojeRpsh": "NEEXISTUJICI",
"stavZdrojeRcns": "NEEXISTUJICI",
"stavZdrojeSzr": "NEEXISTUJICI",
"stavZdrojeDph": "NEEXISTUJICI",
"stavZdrojeSd": "NEEXISTUJICI",
"stavZdrojeIr": "NEEXISTUJICI",
"stavZdrojeCeu": "NEEXISTUJICI",
"stavZdrojeRs": "NEEXISTUJICI",
"stavZdrojeRed": true,
"stavZdrojeMonitor": "NEEXISTUJICI"
}
}
1 change: 1 addition & 0 deletions tests/src/E2E/Ares/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected static function getMask(): string
protected function provideCore(): array
{
return [
['26577321'], // address from dalsiUdaje[0]->sidlo[0]->sidlo
['25528351'], // diff address
['67909442'], // create date does not exist
['27735753'], // create date does not exist
Expand Down

0 comments on commit 25ebbb0

Please sign in to comment.