From 7aeaa3e9757b5bced5aa02b690e7bde0befa77c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Mat=C4=9Bj=C4=8Dek?= Date: Tue, 20 Aug 2024 10:48:43 +0200 Subject: [PATCH] fix(zip): fallback from pscTxt --- src/Ares/Core/JsonToDataTransformer.php | 5 ++- src/Tools/Strings.php | 6 ++++ tests/fixtures/ares/00841811.json | 38 ++++++++++++++++++++ tests/fixtures/ares/25528351.json | 46 +++++++++++++++++++++++++ tests/fixtures/ares/61682039.json | 4 +-- tests/src/E2E/Ares/CoreTest.php | 4 ++- tests/src/UseStoredFile.php | 2 +- 7 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 tests/fixtures/ares/00841811.json create mode 100644 tests/fixtures/ares/25528351.json diff --git a/src/Ares/Core/JsonToDataTransformer.php b/src/Ares/Core/JsonToDataTransformer.php index 35ec44c..35d4101 100644 --- a/src/Ares/Core/JsonToDataTransformer.php +++ b/src/Ares/Core/JsonToDataTransformer.php @@ -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)) { [ diff --git a/src/Tools/Strings.php b/src/Tools/Strings.php index aad0c85..79b1425 100644 --- a/src/Tools/Strings.php +++ b/src/Tools/Strings.php @@ -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) */ diff --git a/tests/fixtures/ares/00841811.json b/tests/fixtures/ares/00841811.json new file mode 100644 index 0000000..fe1b26c --- /dev/null +++ b/tests/fixtures/ares/00841811.json @@ -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 + } +} \ No newline at end of file diff --git a/tests/fixtures/ares/25528351.json b/tests/fixtures/ares/25528351.json new file mode 100644 index 0000000..21b1117 --- /dev/null +++ b/tests/fixtures/ares/25528351.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/fixtures/ares/61682039.json b/tests/fixtures/ares/61682039.json index 72c131a..d8e8ecf 100644 --- a/tests/fixtures/ares/61682039.json +++ b/tests/fixtures/ares/61682039.json @@ -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": [ diff --git a/tests/src/E2E/Ares/CoreTest.php b/tests/src/E2E/Ares/CoreTest.php index b1a44e7..1390c6f 100644 --- a/tests/src/E2E/Ares/CoreTest.php +++ b/tests/src/E2E/Ares/CoreTest.php @@ -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'], @@ -43,6 +44,7 @@ protected function provideCore(): array ['49812670'], // s.r.o. ['62413686'], // k.s. ['87744473'], // freelancer + ['00841811'], // Němčice ]; } @@ -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); } diff --git a/tests/src/UseStoredFile.php b/tests/src/UseStoredFile.php index 415845f..51f36a6 100644 --- a/tests/src/UseStoredFile.php +++ b/tests/src/UseStoredFile.php @@ -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));