• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

h4kuna / ares / 8781737527

22 Apr 2024 09:27AM UTC coverage: 89.744% (+0.6%) from 89.112%
8781737527

push

github

h4kuna
feat(VIES): add checker VAT in EU

41 of 45 new or added lines in 8 files covered. (91.11%)

350 of 390 relevant lines covered (89.74%)

0.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.77
/src/Ares/Core/ContentProvider.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Ares\Ares\Core;
4

5
use Generator;
6
use h4kuna\Ares\Adis;
7
use h4kuna\Ares\Ares\Client;
8
use h4kuna\Ares\Ares\Helper;
9
use h4kuna\Ares\Ares\Sources;
10
use h4kuna\Ares\Exceptions\IdentificationNumberNotFoundException;
11
use h4kuna\Ares\Tools\Batch;
12

13
final class ContentProvider
14
{
15
        private const BATCH = 100; // max identification numbers per request
16

17

18
        public function __construct(
1✔
19
                private JsonToDataTransformer $jsonTransformer,
20
                private Client $client,
21
                private Adis\ContentProvider $adisContentProvider,
22
        )
23
        {
24
        }
1✔
25

26

27
        public function getClient(): Client
28
        {
NEW
29
                return $this->client;
×
30
        }
31

32

33
        /**
34
         * @template KeyName
35
         * @param array<KeyName, string|int> $identificationNumbers
36
         * @return Generator<(int&KeyName)|(KeyName&string), Data>
37
         */
38
        public function loadByIdentificationNumbers(array $identificationNumbers): Generator
1✔
39
        {
40
                $duplicity = Batch::checkDuplicities($identificationNumbers, fn (string $in) => Helper::normalizeIN($in));
1✔
41
                $chunks = Batch::chunk($duplicity, self::BATCH);
1✔
42

43
                foreach ($chunks as $INs) {
1✔
44
                        $responseData = $this->client->searchEndpoint(Sources::CORE, [
1✔
45
                                'ico' => $INs,
1✔
46
                                'pocet' => self::BATCH,
1✔
47
                        ])->ekonomickeSubjekty ?? [];
1✔
48

49
                        $results = $map = [];
1✔
50
                        foreach ($responseData as $item) {
1✔
51
                                $data = $this->jsonTransformer->transform($item);
1✔
52
                                $results[] = $data;
1✔
53
                                if ($data->tin !== null) {
1✔
54
                                        $map[$data->in] = $data->tin;
1✔
55
                                }
56
                        }
57

58
                        $subjects = iterator_to_array($this->adisContentProvider->statusBusinessSubjects($map));
1✔
59

60
                        foreach ($results as $data) {
1✔
61
                                foreach ($duplicity[$data->in] as $name) {
1✔
62
                                        if (isset($subjects[$data->in])) {
1✔
63
                                                $data->setAdis($subjects[$data->in]);
1✔
64
                                        }
65
                                        yield $name => $data;
1✔
66
                                }
67
                        }
68
                }
69
        }
1✔
70

71

72
        /**
73
         * @throws IdentificationNumberNotFoundException
74
         */
75
        public function load(string $in): Data
1✔
76
        {
77
                $json = $this->client->useEndpoint(Sources::CORE, $in);
1✔
78

79
                $data = $this->jsonTransformer->transform($json);
1✔
80
                if ($data->tin !== null) {
1✔
81
                        $adis = $this->adisContentProvider->statusBusinessSubject($data->tin);
1✔
82
                        $data->setAdis($adis);
1✔
83
                }
84

85
                return $data;
1✔
86
        }
87

88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc