Skip to content

Commit

Permalink
Ares: support new API
Browse files Browse the repository at this point in the history
  • Loading branch information
h4kuna committed Sep 12, 2023
1 parent 5c49b80 commit a87cbaf
Show file tree
Hide file tree
Showing 64 changed files with 8,194 additions and 2,935 deletions.
Binary file added .doc/payment.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.doc export-ignore
changelog.md export-ignore
tests export-ignore
phpstan.neon export-ignore
README.md export-ignore
example export-ignore
21 changes: 21 additions & 0 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Static Analysis (only informative)

on:
push:
branches:
- master

jobs:
phpstan:
name: PHPStan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
- run: composer phpstan -- --no-progress
continue-on-error: true # is only informative
45 changes: 28 additions & 17 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,32 @@ jobs:
name: output
path: tests/**/output

lowest_dependencies:
name: Lowest Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable
- run: composer tests

# code_coverage:
# name: Code Coverage
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - uses: shivammathur/setup-php@v2
# with:
# php-version: 8.0
# extensions: json, mbstring, tokenizer, fileinfo
# coverage: none
#
# - run: composer install --no-progress --prefer-dist
# - run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
# - run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
# - env:
# COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
code_coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: shivammathur/setup-php@v2
with:
php-version: 8.0
coverage: none

- run: composer install --no-progress --prefer-dist
- run: vendor/bin/tester -p phpdbg tests -s -C --coverage ./coverage.xml --coverage-src ./src
- run: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.4.3/php-coveralls.phar
- env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: php php-coveralls.phar --verbose --config tests/.coveralls.yml
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
composer.lock
/**/output/
/vendor/
/AresRestApi-verejne.json
/coverage.html
37 changes: 25 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@

More information about versions is in [changelog](changelog.md).

## Support development by QR code

![QR payment](./.doc/payment.png)

Thank you :)

## Installation to project

The best way to install h4kuna/ares is using Composer:

```sh
$ composer require h4kuna/ares
composer require h4kuna/ares
```

Download information about customer via his IN.
Expand All @@ -22,40 +29,46 @@ Download information about customer via his IN.
Load data by one identification number

```php
$ares = (new h4kuna\Ares\AresFactory())->create();
use h4kuna\Ares;
$ares = (new Ares\AresFactory())->create();
try {
$response = $ares->loadBasic('87744473');
/* @var $response h4kuna\Ares\Basic\Data */
/* @var $response Ares\Ares\Core\Data */
var_dump($response);
} catch (h4kuna\Ares\Exceptions\IdentificationNumberNotFoundException $e) {
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}
```

Load data by many identification numbers
Load data by many identification numbers. Limit by ARES is 100 items, but library chunk it and check duplicity.

```php
/** @var h4kuna\Ares\Ares $ares */
use h4kuna\Ares;
/** @var Ares\Ares $ares */
$numbers = ['25596641', '26713250', '27082440', '11111111'];
$res = $ares->loadBasicMulti($numbers);

if ($res[$ares::RESULT_FAILED] !== []) {
var_dump($res[$ares::RESULT_FAILED]);
try {
$dataGenerator = $ares->loadBasicMulti($numbers);
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}

foreach ($res[$ares::RESULT_SUCCESS] as $r) {
foreach ($dataGenerator as $r) {
var_dump($r->company);
}
```

## Data Box

```php
/** @var h4kuna\Ares\Ares $ares */
use h4kuna\Ares;
/** @var Ares\Ares $ares */
try {
$response = $ares->loadDataBox('87744473');
var_dump($response->ISDS);
} catch (h4kuna\Ares\Exceptions\ConnectionException $e) {
} catch (h4kuna\Ares\Exceptions\ServerResponseException $e) {
// catch error
}
```
36 changes: 36 additions & 0 deletions bin/endpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use h4kuna\Ares;

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

$IN = trim($argv[1] ?? '27082440');

$ares = (new Ares\AresFactory())->create();
try {
$response = $ares->loadBasic($IN);
/* @var $response Ares\Ares\Core\Data */
$response->original = null;
dump($response);
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}

foreach ($response->sources as $name => $exists) {
if ($exists === false || Ares\Ares\Helper::endpointExists($name) === false) {
continue;
}
dump(Ares\Ares\Helper::prepareUrl($name, $IN));

try {
$result = $ares->getAresRequestProvider()->useEndpoint($name, $IN);
dump($result);
} catch (Ares\Exceptions\IdentificationNumberNotFoundException $e) {
// log identification number, why is bad? Or make nothing.
} catch (Ares\Exceptions\ServerResponseException $e) {
// no response from server or broken json
}
}
16 changes: 16 additions & 0 deletions bin/legal-form
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env php
<?php declare(strict_types=1);

use h4kuna\Ares;

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

$ares = (new Ares\AresFactory())->create();
$result = $ares->getAresRequestProvider()->searchEndpoint(Ares\Ares\Sources::DIAL, [
'kodCiselniku' => 'PravniForma',
'zdrojCiselniku' => 'res',
])->ciselniky[0]->polozkyCiselniku;

foreach ($result as $item) {
dump($item);
}
62 changes: 50 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,43 @@
v2.0.0
======
# v3.0.0

- podpora nového API ARES2
- v [bin](./bin) jsou spustitelné ukázky, jak se dostat na číselníky a jak na ostatní endpointy
- pro IČO je vyžadován formát \d{8}, pokud je kratší, knihovna sama doplní nuly zleva
- očekávám že se změní url API, pro tento případ je připravená `public static h4kuna\Ares\Ares\Helper::$baseUrl`, kterou lze nahradit, bez nutnosti vyčkávat na nový release
- podobně lze dopnit nebo upravit url adresy endpointů
- php 8.0+

### Třidy

- h4kuna\Ares\Ares
- metoda `loadBasic()` nově vrací [DataInterface](./src/Ares/Core/DataInterface.php) implementace je původní [Data](./src/Ares/Core/Data.php)
- metoda `loadBasicMulti()`
- nově vrací Generator nikoliv pole
- vrací jen existující záznamy, třída Error byla smazána, nemá náhradu
- počet IČO není omezen, interně se rozdělí na dávky po 100 záznamech a ještě před tím se odeberou duplicity, při iteraci duplicity zůstanou, jen objekty budou mít stejné reference


- h4kuna\Ares\Ares\Core\Data
- zmizela metoda `psu()` bez náhrady, podobné informace jsou ve vlastnosti `$sources`
- zmizela metoda `isGroupVat()` ARES již vrací DIČ pro skupinové DPH
- odstraněné vlastnosti `$court`, `$file_number`, `$court_all` jsou dostupné na jiném endpointu, `Sources::SERVICE_VR`
- DIČ je nově bez prefixu `CZ`, vlastnost `$tin` z důvodu zpětné kompatibility, prefix nese, nová vlastnost `$vat_id` prefix nemá
- vlastnost `$created` je podle mě momentálně rozbitá, pro Alzu datumVzniku je 2003-08-26, ale dostávám 2023-09-04 (nahlášeno)
- původní název `h4kuna\Ares\Basic\Data`, ale je zde [aliases.php](./src/aliases.php) který zajistí zpětnou kompatibilitu a bude hlásit aby jste si třídu přejmnovali, nicméně stará třída bude fungovat
- už není možnost do metody `toArray()` předat vlastní pole pro úpravu mapování, pro změnu entity za vlastní využijte interface [JsonToDataTransformerInterface](./src/Ares/Core/JsonToDataTransformerInterface.php)
- přidané vlastnosti `$country` a `$country_code`


- h4kuna\Ares\Exceptions\ConnectionException
- nastavena jako deprecated, zpětně funkční
- nahrazena h4kuna\Ares\Exceptions\ServerResponseException

### Závěrem

Pokud si pohlídáte s jakými vlastnostmi pracujete a nebudou tam ty smazané, tak je to zpětně kompatibilní. Pracujete-li s `Ares::loadBasicMulti()` je potřeba vzít v potaz že to je zpětně nekompatibilní a nově se vrací Generator.

# v2.0.0

- remove support php < 7.4
- serialized date use RFC3339 instead of ISO8601, because ISO is deprecated by php
- removed method Ares::getData()
Expand All @@ -10,19 +48,19 @@ v2.0.0
- prepared AresFactory::create() for instance Ares class
- Data::$tin is null if value is Skupinove_DPH

v1.4.0
======
# v1.4.0

- remove support php < 7.1
- exceptions move to files -> one class is one file and change namespace


v1.3.0
======
# v1.3.0

- remove support for php 5.5
- add Factory provide new instances Guzzle, Data, DataProvider

v1.2.0
======
# v1.2.0

- interface IData was removed
- change data keys:
- person -> is_person
Expand All @@ -33,15 +71,15 @@ v1.2.0
- class Data extends Messenger
- class Data suggest property

v1.1.3
======
# v1.1.3

- method Ares::loadData throw IdentificationNumberNotFoundException if find nothing
- rename InNotFoundExceptions -> IdentificationNumberNotFoundException
- rename vat_pay -> vat_payer and interface IData
- try download exists item if is faild try download item with non-exists parameter

v1.1.2
======
# v1.1.2

- method Ares::loadData throw InNotFoundExceptions if find nothing
- attribute vat_pay in Data is bool instanceof empty string and string 1
- attribute created in Data is Datetime instanceof ISO date
Expand Down
24 changes: 13 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,25 @@
}
],
"autoload": {
"files": [
"src/aliases.php"
],
"psr-4": {
"h4kuna\\Ares\\": "src/"
}
},
"files": [
"src/aliases.php"
]
},
"autoload-dev": {
"psr-4": {
"h4kuna\\Ares\\Tests\\": "tests/src/"
"h4kuna\\Ares\\Tests\\": "tests/src"
}
},
"require": {
"php": ">=8.0",
"ext-curl": "*",
"ext-json": "*",
"ext-simplexml": "*",
"h4kuna/memoize": "^0.1.4",
"nette/utils": "^3.0 || ^4.0",
"psr/http-client": "^1.0",
"psr/http-factory": "^1.0",
"psr/http-message": "^1.0 || ^2.0"
"psr/http-factory": "^1.0"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.5",
Expand All @@ -42,11 +40,15 @@
"tracy/tracy": "^2.9"
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
},
"scripts": {
"phpstan": "vendor/bin/phpstan analyse",
"tests": "vendor/bin/tester -s -j 6 --colors 1 -s -C tests/src"
"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"
},
"suggest": {
"guzzlehttp/guzzle": "As default implementation for PSR standards."
Expand Down
14 changes: 3 additions & 11 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,11 @@ parameters:
- tests
ignoreErrors:
-
message: "#^Variable property access on SimpleXMLElement\\.$#"
count: 4
path: src/Basic/ContentProvider.php
-
message: "#^Variable property access on \\$this\\(h4kuna\\\\Ares\\\\Basic\\\\Data\\)\\.$#"
count: 1
path: src/Basic/Data.php
-
message: "#^Call to an undefined method h4kuna\\\\Ares\\\\BusinessList\\\\ContentProvider\\:\\:onAfterContent\\(\\)\\.$#"
message: "#^Variable property access on \\$this\\(h4kuna\\\\Ares\\\\Ares\\\\Core\\\\Data\\)\\.$#"
count: 1
path: src/BusinessList/ContentProvider.php
path: src/Ares/Core/Data.php
-
message: "#^If condition is always false.$#"
message: "#^If condition is always false\\.$#"
count: 1
path: src/aliases.php

Expand Down
Loading

0 comments on commit a87cbaf

Please sign in to comment.