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

h4kuna / ares / 9022201619

07 May 2024 04:36AM UTC coverage: 89.286%. Remained the same
9022201619

push

github

h4kuna
fix(tests)

2 of 3 new or added lines in 1 file covered. (66.67%)

350 of 392 relevant lines covered (89.29%)

0.89 hits per line

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

92.86
/src/Vies/Client.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\Ares\Vies;
4

5
use h4kuna\Ares\Exceptions\ServerResponseException;
6
use h4kuna\Ares\Http\TransportProvider;
7
use stdClass;
8

9
/**
10
 * @phpstan-type ViesResponse object{countryCode: string, vatNumber: string, requestDate: string, valid: bool, requestIdentifier: string, name: string, address: string, traderName: string, traderStreet: string, traderPostalCode: string, traderCity: string, traderCompanyType: string, traderNameMatch: string, traderStreetMatch: string, traderPostalCodeMatch: string, traderCityMatch: string, traderCompanyTypeMatch: string}
11
 */
12
final class Client
13
{
14
        public static string $url = 'https://ec.europa.eu/taxation_customs/vies/rest-api';
15

16

17
        public function __construct(private TransportProvider $transportProvider)
1✔
18
        {
19
        }
1✔
20

21

22
        /**
23
         * @return ViesResponse
24
         *
25
         * @throws ServerResponseException
26
         */
27
        public function checkVatNumber(ViesEntity $viesEntity): object
1✔
28
        {
29
                $request = $this->transportProvider->createJsonRequest(static::$url . '/check-vat-number', $viesEntity->toParam());
1✔
30
                $response = $this->transportProvider->response($request);
1✔
31

32
                $data = $this->transportProvider->toJson($response);
1✔
33
                if (isset($data->errorWrappers[0], $data->errorWrappers[0]->error)) {
1✔
34
                        if (isset($data->errorWrappers[0]->message)) {
1✔
35
                                throw new ServerResponseException(sprintf('%s: %s', $data->errorWrappers[0]->error, $data->errorWrappers[0]->message));
1✔
36
                        }
37

NEW
38
                        throw new ServerResponseException($data->errorWrappers[0]->error);
×
39
                }
40

41
                /** @var ViesResponse $data */
42
                return $data;
1✔
43
        }
44

45

46
        public function status(): stdClass
47
        {
48
                $request = $this->transportProvider->createRequest(static::$url . '/check-status');
1✔
49
                $response = $this->transportProvider->response($request);
1✔
50

51
                return $this->transportProvider->toJson($response);
1✔
52
        }
53
}
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