Skip to content

Commit

Permalink
I don't understand why but for this 'res' source, the country code is…
Browse files Browse the repository at this point in the history
… returned as "1", yes a string, instead of "cz", so let's deal with that

It could be easily removed in the future, and there's a test for it (the one for the company with id 00256081), so if it is removed and it shouldn't be, I should know about it rather soon.

Fix #242
  • Loading branch information
spaze committed Oct 16, 2023
1 parent dc7fbf3 commit 8524ef3
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions site/app/CompanyInfo/CompanyRegisterAres.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public function getDetails(string $companyId): CompanyInfoDetails
'psc' => Expect::int(),
'kodStatu' => Expect::string(),
])->otherItems(),
'primarniZdroj' => Expect::string(),
])->otherItems();
/** @var object{ico:string, dic:string|null, obchodniJmeno:string, sidlo:object{nazevObce:string, nazevUlice:string, cisloDomovni:int, cisloOrientacni:int, cisloOrientacniPismeno:string, psc:int, kodStatu:string}} $data */
/** @var object{ico:string, dic:string|null, obchodniJmeno:string, sidlo:object{nazevObce:string, nazevUlice:string, cisloDomovni:int, cisloOrientacni:int, cisloOrientacniPismeno:string, psc:int, kodStatu:string}, primarniZdroj:string|null} $data */
$data = $this->schemaProcessor->process($schema, Json::decode($content));
} catch (JsonException | ValidationException $e) {
throw new CompanyInfoException($e->getMessage(), previous: $e);
Expand All @@ -84,7 +85,7 @@ public function getDetails(string $companyId): CompanyInfoDetails
$streetAndNumber,
$data->sidlo->nazevObce,
(string)$data->sidlo->psc,
strtolower($data->sidlo->kodStatu),
$this->resolveCountryCode($data->primarniZdroj, $data->sidlo->kodStatu, $companyId),
);
}

Expand Down Expand Up @@ -122,4 +123,20 @@ private function formatStreet(?string $city, ?string $street, ?int $houseNumber,
return $result;
}


/**
* @throws CompanyInfoException
*/
private function resolveCountryCode(?string $source, string $code, string $companyId): string
{
if ($source === 'res') {
if ($code === '1') {
return 'cz';
} else {
throw new CompanyInfoException("Invalid country code {$code} from source {$source} for company {$companyId}");
}
}
return strtolower($code);
}

}

0 comments on commit 8524ef3

Please sign in to comment.