File tree Expand file tree Collapse file tree 4 files changed +14
-10
lines changed
Expand file tree Collapse file tree 4 files changed +14
-10
lines changed Original file line number Diff line number Diff line change @@ -30,8 +30,8 @@ public function checkVatNumber(ViesEntity $viesEntity): object
3030 $ response = $ this ->transportProvider ->response ($ request );
3131
3232 $ data = $ this ->transportProvider ->toJson ($ response );
33- if (array_key_exists ( 0 , $ data ->errorWrappers ) && property_exists ( $ data ->errorWrappers [0 ], ' error ' ) ) {
34- if (property_exists ($ data ->errorWrappers [0 ], ' message ' )) {
33+ if (isset ( $ data ->errorWrappers [ 0 ]-> error ) && $ data ->errorWrappers [0 ] instanceof stdClass ) {
34+ if (isset ($ data ->errorWrappers [0 ]-> message )) {
3535 throw new ServerResponseException (sprintf ('%s: %s ' , $ data ->errorWrappers [0 ]->error , $ data ->errorWrappers [0 ]->message ));
3636 }
3737
Original file line number Diff line number Diff line change 22
33namespace h4kuna \Ares \Vies ;
44
5+ use h4kuna \Ares \Exceptions \InvalidStateException ;
56use h4kuna \Ares \Exceptions \ServerResponseException ;
67use Nette \Utils \Strings ;
78use stdClass ;
@@ -25,14 +26,12 @@ public function __construct(private Client $client)
2526 public function checkVat (string |ViesEntity $ vatNumber ): object
2627 {
2728 if (is_string ($ vatNumber )) {
28- $ match = Strings::match ($ vatNumber , '/(?<country>[A-Z]+)(?<number>\d+)/ ' );
29- if (isset ($ match ['country ' ], $ match ['number ' ])) {
30- ['country ' => $ country , 'number ' => $ number ] = $ match ;
31- } else {
32- $ country = '' ;
33- $ number = $ vatNumber ;
29+ $ match = Strings::match ($ vatNumber , '/(?<country>[A-Z]{2})/ ' );
30+ if (isset ($ match ['country ' ]) === false ) {
31+ throw new InvalidStateException ('Use class ViesEntity instead of string. ' );
3432 }
35- $ viesEntity = new ViesEntity ($ number , $ country );
33+
34+ $ viesEntity = new ViesEntity (substr ($ vatNumber , 2 ), $ match ['country ' ]);
3635 } else {
3736 $ viesEntity = $ vatNumber ;
3837 }
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ public function __construct(
2828 public function toParam (): array
2929 {
3030 /** @var viesParam $data */
31- $ data = array_filter (get_object_vars ($ this ), fn ($ value ) => $ value !== '' && $ value !== null );
31+ $ data = array_filter (get_object_vars ($ this ), static fn ($ value ) => $ value !== '' && $ value !== null );
3232
3333 return $ data ;
3434 }
Original file line number Diff line number Diff line change @@ -21,6 +21,11 @@ final class ClientTest extends TestCase
2121 public static function dataCheckVat (): array
2222 {
2323 return [
24+ [
25+ function (self $ self ) {
26+ $ self ->assertCheckVat ('ATU73528319 ' , true );
27+ },
28+ ],
2429 [
2530 function (self $ self ) {
2631 $ self ->assertCheckVat ('CZ27082440 ' , true );
You can’t perform that action at this time.
0 commit comments