Skip to content

Commit

Permalink
- remove interfaces, fix phpdoc
Browse files Browse the repository at this point in the history
- info for properties vat_payer, tin, vat_id, but think how fix it
- Sources::SERVICE_CORE renamed Sources::CORE
- Data::$sources, keep name of all services, if service 'AKTIVNI' is bool true else is string
  • Loading branch information
h4kuna committed Sep 14, 2023
1 parent 49d7f71 commit 4a0395d
Show file tree
Hide file tree
Showing 26 changed files with 455 additions and 137 deletions.
126 changes: 126 additions & 0 deletions soap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?php declare(strict_types=1);

require __DIR__ . '/vendor/autoload.php';

$wsdl = 'https://adisrws.mfcr.cz/dpr/axis2/services/rozhraniCRPDPH.rozhraniCRPDPHSOAP';

class StatusNespolehlivyPlatceRequest
{
public function __construct(public string $dic)
{
}

}

class StatusNespolehlivyPlatceRozsirenyResponse
{

}

$soap = new SoapClient($wsdl, [
'soap_version' => SOAP_1_1,
'cache_wsdl' => WSDL_CACHE_MEMORY,
'classmap' => [
'StatusNespolehlivyPlatceRequest' => StatusNespolehlivyPlatceRequest::class,
],
]);


//array (23)
// 0 => string
//| 'struct StatusNespolehlivyPlatceRequest {\n
// | DICType dic;\n
// | }'
// 1 => string
//| 'struct StatusNespolehlivyPlatceResponse {\n
// | StatusType status;\n
// | InformaceOPlatciType statusPlatceDPH;\n
// | }'
// 2 => string
//| 'struct StatusNespolehlivyPlatceRozsirenyResponse {\n
// | StatusType status;\n
// | InformaceOPlatciRozsireneType statusPlatceDPH;\n
// | }'
// 3 => string
//| 'struct StatusNespolehlivySubjektRozsirenyResponse {\n
// | StatusType status;\n
// | InformaceOSubjektuRozsireneType statusSubjektu;\n
// | }'
// 4 => string
//| 'struct SeznamNespolehlivyPlatceResponse {\n
// | StatusType status;\n
// | InformaceOPlatciType statusPlatceDPH;\n
// | }'
// 5 => string
//| 'struct SeznamNespolehlivyPlatceRequest {\n
// | }'
// 6 => 'string DICType'
// 7 => string
//| 'struct InformaceOPlatciType {\n
// | SeznamZverejnenychUctuType zverejneneUcty;\n
// | DICType dic;\n
// | NespolehlivyPlatceType nespolehlivyPlatce;\n
// | date datumZverejn ... cisloFu;\n
// | }'
// 8 => 'string anonymous8'
// 9 => string
//| 'struct InformaceOPlatciRozsireneType {\n
// | string nazevSubjektu;\n
// | Adresa adresa;\n
// | }'
// 10 => string
//| 'struct InformaceOSubjektuRozsireneType {\n
// | string nazevSubjektu;\n
// | Adresa adresa;\n
// | TypSubjektuDPHType typSubjektu;\n
// | }'
// 11 => string
//| 'struct Adresa {\n
// | string uliceCislo;\n
// | string castObce;\n
// | string mesto;\n
// | string psc;\n
// | string stat;\n
// | }'
// 12 => 'string NespolehlivyPlatceType'
// 13 => 'string TypSubjektuDPHType'
// 14 => 'string BezVypisuUctuType'
// 15 => string
//| 'struct StandardniUcetType {\n
// | anonymous16 predcisli;\n
// | anonymous17 cislo;\n
// | anonymous18 kodBanky;\n
// | }'
// 16 => 'string anonymous16'
// 17 => 'string anonymous17'
// 18 => 'string anonymous18'
// 19 => string
//| 'struct ZverejnenyUcetType {\n
// | StandardniUcetType standardniUcet;\n
// | NestandardniUcetType nestandardniUcet;\n
// | date datumZverejneni;\n
// | date datumZverejneniUkonceni;\n
// | }'
// 20 => string
//| 'struct SeznamZverejnenychUctuType {\n
// | ZverejnenyUcetType ucet;\n
// | }'
// 21 => string
//| 'struct NestandardniUcetType {\n
// | string cislo;\n
// | }'
// 22 => string
//| 'struct StatusType {\n
// | date odpovedGenerovana;\n
// | int statusCode;\n
// | string statusText;\n
// | BezVypisuUctuType bezVypisuUctu;\n
// | }'

//0 => 'StatusNespolehlivyPlatceResponse getStatusNespolehlivyPlatce(StatusNespolehlivyPlatceRequest $parameters)'
//1 => 'SeznamNespolehlivyPlatceResponse getSeznamNespolehlivyPlatce(SeznamNespolehlivyPlatceRequest $parameters)'
//2 => 'StatusNespolehlivyPlatceRozsirenyResponse getStatusNespolehlivyPlatceRozsireny(StatusNespolehlivyPlatceRozsirenyResponse $parameters)'
//3 => 'StatusNespolehlivySubjektRozsirenyResponse getStatusNespolehlivySubjektRozsireny(StatusNespolehlivyPlatceRequest $parameters)'

//dumpe($soap->__getTypes());
dumpe($soap->getStatusNespolehlivyPlatce(new StatusNespolehlivyPlatceRequest('CZ49240901')));
27 changes: 13 additions & 14 deletions src/Ares.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Generator;
use h4kuna\Ares\Ares\Core\Data;
use h4kuna\Ares\Ares\Core\DataInterface;
use h4kuna\Ares\Exceptions\IdentificationNumberNotFoundException;
use h4kuna\Memoize\MemoryStorage;
use stdClass;
Expand All @@ -28,27 +27,22 @@ public function getAresClient(): Ares\Client


/**
* @template NAME
* @param array<NAME, string|int> $identificationNumbers
* @return Generator<NAME, Data>
* @template KeyName
* @param array<KeyName, string|int> $identificationNumbers
* @return Generator<(int&KeyName)|(KeyName&string), Data>
*/
public function loadBasicMulti(array $identificationNumbers): Generator
{
/** @var Generator<NAME, Data> $data */
$data = $this->aresContentProvider()->loadByIdentificationNumbers($identificationNumbers);
return $data;
return $this->aresContentProviderCache()->loadByIdentificationNumbers($identificationNumbers);
}


/**
* @return Data
* @throws IdentificationNumberNotFoundException
*/
public function loadBasic(string $in): DataInterface
public function loadBasic(string $in): Data
{
/** @var Data $data */
$data = $this->aresContentProvider()->load($in);
return $data;
return $this->aresContentProviderCache()->load($in);
}


Expand All @@ -60,8 +54,13 @@ public function loadDataBox(string $in): stdClass

protected function aresContentProvider(): Ares\Core\ContentProvider
{
return $this->memoize(__METHOD__, fn (
) => new Ares\Core\ContentProvider(new Ares\Core\JsonToDataTransformer(), $this->aresClient));
return new Ares\Core\ContentProvider(new Ares\Core\JsonToDataTransformer(), $this->getAresClient());
}


private function aresContentProviderCache(): Ares\Core\ContentProvider
{
return $this->memoize(__METHOD__, fn () => $this->aresContentProvider());
}

}
4 changes: 2 additions & 2 deletions src/Ares/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(


/**
* @param Sources::SERVICE_* $key
* @param Sources::SERVICE_*|Sources::CORE $key
* @param array<string, mixed> $data
*/
public function searchEndpoint(string $key, array $data = []): stdClass
Expand All @@ -35,7 +35,7 @@ public function searchEndpoint(string $key, array $data = []): stdClass


/**
* @param Sources::SERVICE_* $key
* @param Sources::SERVICE_*|Sources::CORE $key
*/
public function useEndpoint(string $key, string $in): stdClass
{
Expand Down
14 changes: 7 additions & 7 deletions src/Ares/Core/ContentProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ final class ContentProvider


public function __construct(
private JsonToDataTransformerInterface $jsonTransformer,
private JsonToDataTransformer $jsonTransformer,
private Client $client,
)
{
}


/**
* @template NAME
* @param array<NAME, string|int> $identificationNumbers
* @return Generator<NAME, DataInterface>
* @template KeyName
* @param array<KeyName, string|int> $identificationNumbers
* @return Generator<(int&KeyName)|(KeyName&string), Data>
*/
public function loadByIdentificationNumbers(array $identificationNumbers): Generator
{
$duplicity = self::checkDuplicities($identificationNumbers);
$chunks = array_chunk(array_keys($duplicity), self::BATCH);

foreach ($chunks as $INs) {
$responseData = $this->client->searchEndpoint(Sources::SERVICE_CORE, [
$responseData = $this->client->searchEndpoint(Sources::CORE, [
'ico' => $INs,
'pocet' => self::BATCH,
])->ekonomickeSubjekty ?? [];
Expand All @@ -50,10 +50,10 @@ public function loadByIdentificationNumbers(array $identificationNumbers): Gener
/**
* @throws IdentificationNumberNotFoundException
*/
public function load(string $in): DataInterface
public function load(string $in): Data
{
try {
$json = $this->client->useEndpoint(Sources::SERVICE_CORE, $in);
$json = $this->client->useEndpoint(Sources::CORE, $in);
} catch (IdentificationNumberNotFoundException) {
$json = $this->client->useEndpoint(Sources::SERVICE_RES, $in);
$records = $json->zaznamy ?? [];
Expand Down
19 changes: 15 additions & 4 deletions src/Ares/Core/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* @phpstan-type DataType array<string, mixed>
*/
class Data implements DataInterface, JsonSerializable, Stringable
class Data implements JsonSerializable, Stringable
{
public bool $active;

Expand All @@ -37,12 +37,20 @@ class Data implements DataInterface, JsonSerializable, Stringable

public ?string $street;

/** <prefix>DIČ */
/**
* <prefix>DIČ
* @todo how fix it, ARES incorrect data in few cases
*/
public ?string $tin;

/** DIČ */
/**
* @todo how fix it, ARES incorrect data in few cases
*/
public ?string $vat_id;

/**
* @todo how fix it, ARES incorrect data in few cases
*/
public bool $vat_payer;

public ?string $zip;
Expand All @@ -57,7 +65,7 @@ class Data implements DataInterface, JsonSerializable, Stringable
public array $nace = [];

/**
* @var array<Sources::SER*, bool>
* @var array<Sources::SER*, true|string>
*/
public array $sources = [];

Expand Down Expand Up @@ -113,6 +121,9 @@ public function __unserialize(array $data): void
}


/**
* @return DataType
*/
public function toArray(): array
{
$data = get_object_vars($this);
Expand Down
9 changes: 0 additions & 9 deletions src/Ares/Core/DataInterface.php

This file was deleted.

9 changes: 6 additions & 3 deletions src/Ares/Core/JsonToDataTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace h4kuna\Ares\Ares\Core;

use h4kuna\Ares\Ares\Helper;
use h4kuna\Ares\Ares\Sources;
use h4kuna\Ares\Tools\Strings;
use stdClass;

final class JsonToDataTransformer implements JsonToDataTransformerInterface
class JsonToDataTransformer
{

public function transform(stdClass $json): Data
Expand All @@ -17,7 +18,9 @@ public function transform(stdClass $json): Data
$data->in = (string) $json->ico;
$data->vat_id = Strings::trimNull($json->dic ?? null);
$data->tin = isset($data->vat_id) ? 'CZ' . $data->vat_id : null;
$data->vat_payer = (bool) $data->vat_id;
$data->sources = Helper::services((array) ($json->seznamRegistraci ?? []));

$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
Expand All @@ -42,7 +45,7 @@ public function transform(stdClass $json): Data
$data->nace = (array) ($json->czNace ?? []);
$data->legal_form_code = (int) $json->pravniForma;
$data->is_person = Helper::isPerson($data->legal_form_code);
$data->sources = Helper::services((array) ($json->seznamRegistraci ?? []));

assert($json->datumVzniku !== null);
$data->created = Strings::createDateTime($json->datumVzniku);
$data->dissolved = Strings::createDateTime($json->datumZaniku ?? null);
Expand Down
11 changes: 0 additions & 11 deletions src/Ares/Core/JsonToDataTransformerInterface.php

This file was deleted.

Loading

0 comments on commit 4a0395d

Please sign in to comment.