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

h4kuna / ares / 20421659198

05 Dec 2025 08:01AM UTC coverage: 89.497% (+4.7%) from 84.821%
20421659198

push

github

h4kuna
Update ARES API 1.3.0

17 of 18 new or added lines in 1 file covered. (94.44%)

1 existing line in 1 file now uncovered.

409 of 457 relevant lines covered (89.5%)

0.89 hits per line

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

97.78
/src/Ares/Helper.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Ares\Ares;
4

5
use h4kuna\Ares\Ares\Core\SubjectType;
6
use h4kuna\Ares\Exception\LogicException;
7
use h4kuna\Ares\Tool\Strings;
8
use Nette\Utils\Strings as NetteStrings;
9

10
/**
11
 * @phpstan-type addressTypeRaw array{street?: string, zip?: string, city?: string, house_number?: string, country?: string}
12
 * @phpstan-type addressType array{street: ?string, zip: ?string, city: ?string, house_number: ?string, country: ?string}
13
 */
14
final class Helper
15
{
16
        public static string $baseUrl = 'https://ares.gov.cz/ekonomicke-subjekty-v-be/rest';
17

18
        /**
19
         * @var array<string, string>
20
         */
21
        public static $endpoints = [
22
                Sources::SERVICE_VR => '/ekonomicke-subjekty-vr/{ico}',
23
                Sources::SERVICE_RES => '/ekonomicke-subjekty-res/{ico}',
24
                Sources::SERVICE_RZP => '/ekonomicke-subjekty-rzp/{ico}',
25
                Sources::SERVICE_NRPZS => '/ekonomicke-subjekty-nrpzs/{ico}',
26
                Sources::SERVICE_RCNS => '/ekonomicke-subjekty-rcns/{ico}',
27
                Sources::SERVICE_RPSH => '/ekonomicke-subjekty-rpsh/{ico}',
28
                Sources::SERVICE_RS => '/ekonomicke-subjekty-rs/{ico}',
29
                Sources::SERVICE_SZR => '/ekonomicke-subjekty-szr/{ico}',
30
                Sources::SERVICE_ROS => '/ekonomicke-subjekty-ros/{ico}',
31
                Sources::SERVICE_CEU => '/ekonomicke-subjekty-ceu/{ico}',
32
                Sources::CORE => '/ekonomicke-subjekty/{ico}',
33
                Sources::DIAL => '/ciselniky-nazevniky/{ico}',
34
        ];
35

36
        private const SERVICES = [
37
                Sources::SERVICE_VR => 'NEEXISTUJICI',
38
                Sources::SERVICE_RES => 'NEEXISTUJICI',
39
                Sources::SERVICE_RZP => 'NEEXISTUJICI',
40
                Sources::SERVICE_NRPZS => 'NEEXISTUJICI',
41
                Sources::SERVICE_RCNS => 'NEEXISTUJICI',
42
                Sources::SERVICE_RPSH => 'NEEXISTUJICI',
43
                Sources::SERVICE_RS => 'NEEXISTUJICI',
44
                Sources::SERVICE_SZR => 'NEEXISTUJICI',
45
                Sources::SERVICE_CEU => 'NEEXISTUJICI',
46
                Sources::SER_NO_DPH => 'NEEXISTUJICI',
47
                Sources::SER_NO_IR => 'NEEXISTUJICI',
48
                Sources::SER_NO_RED => 'NEEXISTUJICI',
49
                Sources::SER_NO_SD => 'NEEXISTUJICI',
50
        ];
51

52

53
        public static function endpointExists(string $source): bool
1✔
54
        {
55
                return isset(self::$endpoints[$source]);
1✔
56
        }
57

58

59
        /**
60
         * @param Sources::SERVICE_*|Sources::DIAL|Sources::CORE $source
61
         */
62
        public static function prepareUrlSearch(string $source): string
1✔
63
        {
64
                return self::prepareUrl($source, 'vyhledat');
1✔
65
        }
66

67

68
        /**
69
         * @param Sources::SERVICE_*|Sources::DIAL|Sources::CORE $source
70
         */
71
        public static function prepareUrl(string $source, string $in): string
1✔
72
        {
73
                if (self::endpointExists($source) === false) {
1✔
UNCOV
74
                        throw new LogicException(sprintf('Endpoint %s does not exists.', $source));
×
75
                }
76

77
                return str_replace(
1✔
78
                        '{ico}',
1✔
79
                        self::normalizeIN($in),
1✔
80
                        self::$baseUrl . self::$endpoints[$source],
1✔
81
                );
82
        }
83

84

85
        /**
86
         * @param array<Sources::SER*, string> $registrations
87
         * @return array<Sources::SER*, true|string>
88
         */
89
        public static function services(array $registrations): array
1✔
90
        {
91
                $map = [];
1✔
92
                foreach ($registrations as $k => $v) {
1✔
93
                        $map[$k] = $v === 'AKTIVNI' ? true : $v;
1✔
94
                }
95

96
                return $map + self::SERVICES;
1✔
97
        }
98

99

100
        public static function houseNumber(
1✔
101
                string $cisloDomovni,
102
                string $cisloOrientacni,
103
                string $cisloOrientacniPismeno
104
        ): ?string
105
        {
106
                $houseNumber = Strings::trimNull(trim($cisloDomovni . '/' . $cisloOrientacni, '/'));
1✔
107
                $houseNumber = $houseNumber === '0' ? null : $houseNumber;
1✔
108

109
                $cisloOrientacniPismeno = Strings::trimNull($cisloOrientacniPismeno);
1✔
110
                if ($cisloOrientacniPismeno !== null) {
1✔
111
                        $houseNumber .= $cisloOrientacniPismeno;
1✔
112
                }
113

114
                return $houseNumber;
1✔
115
        }
116

117

118
        public static function isPerson(int $legalForm): bool
1✔
119
        {
120
                return match ($legalForm) {
121
                        SubjectType::OSVC, 105, 107, 424, 425 => true,
1✔
122
                        default => false,
1✔
123
                };
124
        }
125

126

127
        public static function normalizeIN(string $in): string
1✔
128
        {
129
                return str_pad($in, 8, '0', STR_PAD_LEFT);
1✔
130
        }
131

132

133
        /**
134
         * @return addressType
135
         */
136
        public static function parseAddress(string $address): array
1✔
137
        {
138
                /** @var ?addressTypeRaw $results */
139
                $results = NetteStrings::match($address, '~^(?<street>.+) (?<house_number>\d+(?:/\d+)?(\w)?)(?:, (?<district>.+?))?, (?<zip>\d{5}) (?<city>.+?)(, (?<country>.+))?$~');
1✔
140

141
                if ($results !== null) {
1✔
142
                        return self::prepareAddressData($results);
1✔
143
                }
144

145
                /** @var ?addressTypeRaw $results */
146
                $results = NetteStrings::match($address, '~^(?<city>.+), (?<zip>\d{5})(?:, (?<district>.+?))?, (?<street>.+), (?<house_number>\d+(?:/\d+)?(\w)?)$~');
1✔
147

148
                return self::prepareAddressData($results ?? []);
1✔
149
        }
150

151

152
        /**
153
         * @param addressTypeRaw $results
154
         * @return addressType
155
         */
156
        private static function prepareAddressData(array $results): array
1✔
157
        {
158
                return [
159
                        'zip' => $results['zip'] ?? null,
1✔
160
                        'street' => $results['street'] ?? null,
1✔
161
                        'house_number' => $results['house_number'] ?? null,
1✔
162
                        'city' => $results['city'] ?? null,
1✔
163
                        'country' => $results['country'] ?? null,
1✔
164
                ];
165
        }
166

167

168
        public static function normalizeTIN(string $tin): string
1✔
169
        {
170
                $upper = strtoupper($tin);
1✔
171
                if (str_starts_with($upper, 'CZ') === false && is_numeric($upper)) {
1✔
172
                        return "CZ$upper";
1✔
173
                }
174

175
                return $upper;
1✔
176
        }
177
}
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

© 2025 Coveralls, Inc