diff --git a/composer.json b/composer.json index e8de185..a501ee1 100644 --- a/composer.json +++ b/composer.json @@ -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." diff --git a/src/Ares/Core/JsonToDataTransformer.php b/src/Ares/Core/JsonToDataTransformer.php index 35d4101..b1e1729 100644 --- a/src/Ares/Core/JsonToDataTransformer.php +++ b/src/Ares/Core/JsonToDataTransformer.php @@ -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, @@ -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; + } + } diff --git a/tests/fixtures/ares/26577321.json b/tests/fixtures/ares/26577321.json new file mode 100644 index 0000000..fdcaa1b --- /dev/null +++ b/tests/fixtures/ares/26577321.json @@ -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" + } +} \ No newline at end of file diff --git a/tests/src/E2E/Ares/CoreTest.php b/tests/src/E2E/Ares/CoreTest.php index 1390c6f..757f549 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 [ + ['26577321'], // address from dalsiUdaje[0]->sidlo[0]->sidlo ['25528351'], // diff address ['67909442'], // create date does not exist ['27735753'], // create date does not exist