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

h4kuna / ares / 22814472412

22 Feb 2026 12:32PM UTC coverage: 89.348% (-0.1%) from 89.497%
22814472412

push

github

web-flow
Merge pull request #51 from h4kuna/php-coding-standard

Add coding standards

40 of 47 new or added lines in 16 files covered. (85.11%)

1 existing line in 1 file now uncovered.

411 of 460 relevant lines covered (89.35%)

0.89 hits per line

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

85.29
/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\ContentProvider as AdisContentProvider;
7
use h4kuna\Ares\Ares\Client;
8
use h4kuna\Ares\Ares\Helper;
9
use h4kuna\Ares\Ares\Sources;
10
use h4kuna\Ares\Exception\AdisResponseException;
11
use h4kuna\Ares\Exception\IdentificationNumberNotFoundException;
12
use h4kuna\Ares\Exception\ResultException;
13
use h4kuna\Ares\Exception\ServerResponseException;
14
use h4kuna\Ares\Tool\Batch;
15
use function iterator_to_array;
16

17
final class ContentProvider
18
{
19

20
        private const BATCH = 100; // max identification numbers per request
21

22
        public function __construct(
1✔
23
                private JsonToDataTransformer $jsonTransformer,
24
                private Client $client,
25
                private AdisContentProvider $adisContentProvider,
26
        )
27
        {
28
        }
1✔
29

30
        public function getClient(): Client
31
        {
32
                return $this->client;
×
33
        }
34

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

49
                foreach ($chunks as $INs) {
1✔
50
                        $responseData = $this->client->searchEndpoint(Sources::CORE, [
1✔
51
                                'ico' => $INs,
1✔
52
                                'pocet' => self::BATCH,
53
                        ])->ekonomickeSubjekty ?? [];
1✔
54

55
                        $results = $map = [];
1✔
56
                        foreach ($responseData as $item) {
1✔
57
                                $data = $this->jsonTransformer->transform($item);
1✔
58
                                $results[] = $data;
1✔
59
                                if ($data->tin !== null) {
1✔
60
                                        $map[$data->in] = $data->tin;
1✔
61
                                }
62
                        }
63

64
                        try {
65
                                $subjects = iterator_to_array($this->adisContentProvider->statusBusinessSubjects($map));
1✔
NEW
66
                        } catch (ServerResponseException $e) {
×
67
                                $subjects = [];
×
68
                        }
69

70
                        foreach ($results as $data) {
1✔
71
                                foreach ($duplicity[$data->in] as $name) {
1✔
72
                                        if (isset($subjects[$data->in])) {
1✔
73
                                                $data->setAdis($subjects[$data->in]);
1✔
74
                                        }
75
                                        yield $name => $data;
1✔
76
                                }
77
                        }
78
                }
79
        }
1✔
80

81
        /**
82
         * @throws AdisResponseException
83
         * @throws IdentificationNumberNotFoundException
84
         * @throws ServerResponseException
85
         */
86
        public function load(string $in): Data
1✔
87
        {
88
                $json = $this->client->useEndpoint(Sources::CORE, $in);
1✔
89

90
                $data = $this->jsonTransformer->transform($json);
1✔
91
                if ($data->tin !== null) {
1✔
92
                        try {
93
                                $adis = $this->adisContentProvider->statusBusinessSubject($data->tin);
1✔
94
                        } catch (ServerResponseException $e) {
×
95
                                throw AdisResponseException::fromServerException($data, $e);
×
96
                        }
97

98
                        $data->setAdis($adis);
1✔
99
                }
100

101
                return $data;
1✔
102
        }
103

104
}
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