Skip to content

Commit

Permalink
fix(zip): fallback from pscTxt
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Aug 20, 2024
1 parent 435e95d commit 7aeaa3e
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 7 deletions.
5 changes: 2 additions & 3 deletions src/Ares/Core/JsonToDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ 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((string) ($json->sidlo->psc ?? '')); // input is int
$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->street = Strings::trimNull($json->sidlo->nazevUlice ?? 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 ?? ''), (string) ($json->sidlo->cisloOrientacni ?? ''), $json->sidlo->cisloOrientacniPismeno ?? '');
$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)) {
[
Expand Down
6 changes: 6 additions & 0 deletions src/Tools/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public static function trimNull(?string $v): ?string
}


public static function replaceSpace(string $string): string
{
return str_replace(' ', '', $string);
}


/**
* @return ($date is null ? null : DateTimeImmutable)
*/
Expand Down
38 changes: 38 additions & 0 deletions tests/fixtures/ares/00841811.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"active": true,
"city": "Němčice",
"company": "Obec Němčice",
"created": "1992-01-01T00:00:00+01:00",
"dissolved": null,
"city_district": "Němčice",
"city_post": null,
"in": "00841811",
"is_person": false,
"legal_form_code": 801,
"house_number": "151",
"street": null,
"district": "Blansko",
"tin": null,
"vat_payer": null,
"zip": "67951",
"country": "Česká republika",
"country_code": "CZ",
"nace": [
"84110"
],
"sources": {
"stavZdrojeVr": "NEEXISTUJICI",
"stavZdrojeRes": true,
"stavZdrojeRzp": "NEEXISTUJICI",
"stavZdrojeNrpzs": "NEEXISTUJICI",
"stavZdrojeRpsh": "NEEXISTUJICI",
"stavZdrojeRcns": "NEEXISTUJICI",
"stavZdrojeSzr": "NEEXISTUJICI",
"stavZdrojeDph": "ZANIKLY",
"stavZdrojeSd": "NEEXISTUJICI",
"stavZdrojeIr": "NEEXISTUJICI",
"stavZdrojeCeu": "NEEXISTUJICI",
"stavZdrojeRs": "NEEXISTUJICI",
"stavZdrojeRed": true
}
}
46 changes: 46 additions & 0 deletions tests/fixtures/ares/25528351.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"active": true,
"city": "Trnava",
"company": "KOMSOL CZ, s.r.o.",
"created": "1998-05-11T00:00:00+02:00",
"dissolved": null,
"city_district": null,
"city_post": null,
"in": "25528351",
"is_person": false,
"legal_form_code": 112,
"house_number": "32",
"street": null,
"district": "Třebíč",
"tin": "CZ25528351",
"vat_payer": true,
"zip": "67401",
"country": "Česká republika",
"country_code": "CZ",
"nace": [
"00",
"022",
"024",
"461",
"471",
"931",
"7490",
"63910",
"82110"
],
"sources": {
"stavZdrojeVr": true,
"stavZdrojeRes": true,
"stavZdrojeRzp": true,
"stavZdrojeNrpzs": "NEEXISTUJICI",
"stavZdrojeRpsh": "NEEXISTUJICI",
"stavZdrojeRcns": "NEEXISTUJICI",
"stavZdrojeSzr": "NEEXISTUJICI",
"stavZdrojeDph": true,
"stavZdrojeSd": "NEEXISTUJICI",
"stavZdrojeIr": "NEEXISTUJICI",
"stavZdrojeCeu": "NEEXISTUJICI",
"stavZdrojeRs": "NEEXISTUJICI",
"stavZdrojeRed": "NEEXISTUJICI"
}
}
4 changes: 2 additions & 2 deletions tests/fixtures/ares/61682039.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"in": "61682039",
"is_person": false,
"legal_form_code": 112,
"house_number": null,
"house_number": "31",
"street": "Mělnická",
"district": null,
"tin": "CZ61682039",
"vat_payer": true,
"zip": null,
"zip": "25002",
"country": "Česká republika",
"country_code": "CZ",
"nace": [
Expand Down
4 changes: 3 additions & 1 deletion 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 [
['25528351'], // diff address
['67909442'], // create date does not exist
['27735753'], // create date does not exist
['61682039'],
Expand All @@ -43,6 +44,7 @@ protected function provideCore(): array
['49812670'], // s.r.o.
['62413686'], // k.s.
['87744473'], // freelancer
['00841811'], // Němčice
];
}

Expand All @@ -53,7 +55,7 @@ protected function provideCore(): array
public function testCore(string $in): void
{
$data = (new Ares\AresFactory())->create()->loadBasic($in);
sort($data->nace, SORT_NUMERIC); // @phpstan-ignore-line
sort($data->nace, SORT_NUMERIC);
$this->assertFile($data->in, $data);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/src/UseStoredFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trait UseStoredFile

protected function assertFile(string $filename, mixed $content): void
{
$filename = strtr($this->getMask(), ['%file%' => $filename]);
$filename = strtr(static::getMask(), ['%file%' => $filename]);
$extension = pathinfo($filename, PATHINFO_EXTENSION);
if (is_file($filename) === false) {
file_put_contents($filename, self::saveContent($content, $extension));
Expand Down

0 comments on commit 7aeaa3e

Please sign in to comment.