@@ -547,7 +547,7 @@ discard block |
||
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
| 550 | - * @param mixed $countryCode |
|
| 550 | + * @param string $countryCode |
|
| 551 | 551 | */ |
| 552 | 552 | public function setCountryCode($countryCode) |
| 553 | 553 | { |
@@ -563,7 +563,7 @@ discard block |
||
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | /** |
| 566 | - * @param mixed $postalCode |
|
| 566 | + * @param string $postalCode |
|
| 567 | 567 | */ |
| 568 | 568 | public function setPostalCode($postalCode) |
| 569 | 569 | { |
@@ -660,6 +660,9 @@ discard block |
||
| 660 | 660 | return $this->getRules(strtoupper($countryCode), $date)['rate']; |
| 661 | 661 | } |
| 662 | 662 | |
| 663 | + /** |
|
| 664 | + * @param \DateTimeInterface|null $date |
|
| 665 | + */ |
|
| 663 | 666 | private function getRules($countryCode, $date): array |
| 664 | 667 | { |
| 665 | 668 | if (!isset($this->taxRules[$countryCode])) { |
@@ -684,7 +687,7 @@ discard block |
||
| 684 | 687 | } |
| 685 | 688 | |
| 686 | 689 | /** |
| 687 | - * @param $vatNumber |
|
| 690 | + * @param string $vatNumber |
|
| 688 | 691 | * |
| 689 | 692 | * @throws VATCheckUnavailableException |
| 690 | 693 | * |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | */ |
| 418 | 418 | private function getClientIP() |
| 419 | 419 | { |
| 420 | - if (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && $_SERVER['HTTP_X_FORWARDED_FOR']) { |
|
| 421 | - $clientIpAddress = $_SERVER['HTTP_X_FORWARDED_FOR']; |
|
| 422 | - } elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR']) { |
|
| 423 | - $clientIpAddress = $_SERVER['REMOTE_ADDR']; |
|
| 420 | + if (isset($_SERVER[ 'HTTP_X_FORWARDED_FOR' ]) && $_SERVER[ 'HTTP_X_FORWARDED_FOR' ]) { |
|
| 421 | + $clientIpAddress = $_SERVER[ 'HTTP_X_FORWARDED_FOR' ]; |
|
| 422 | + } elseif (isset($_SERVER[ 'REMOTE_ADDR' ]) && $_SERVER[ 'REMOTE_ADDR' ]) { |
|
| 423 | + $clientIpAddress = $_SERVER[ 'REMOTE_ADDR' ]; |
|
| 424 | 424 | } else { |
| 425 | 425 | $clientIpAddress = ''; |
| 426 | 426 | } |
@@ -440,11 +440,11 @@ discard block |
||
| 440 | 440 | $ip = $this->getClientIP(); |
| 441 | 441 | $url = self::GEOCODE_SERVICE_URL.$ip; |
| 442 | 442 | $result = file_get_contents($url); |
| 443 | - switch ($result[0]) { |
|
| 443 | + switch ($result[ 0 ]) { |
|
| 444 | 444 | case '1': |
| 445 | 445 | $data = explode(';', $result); |
| 446 | 446 | |
| 447 | - return $data[1]; |
|
| 447 | + return $data[ 1 ]; |
|
| 448 | 448 | break; |
| 449 | 449 | default: |
| 450 | 450 | return false; |
@@ -462,7 +462,7 @@ discard block |
||
| 462 | 462 | { |
| 463 | 463 | $taxKey = 'vat_calculator.rules.'.strtoupper($countryCode); |
| 464 | 464 | |
| 465 | - return isset($this->taxRules[strtoupper($countryCode)]) || (isset($this->config) && $this->config->has($taxKey)); |
|
| 465 | + return isset($this->taxRules[ strtoupper($countryCode) ]) || (isset($this->config) && $this->config->has($taxKey)); |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -640,39 +640,39 @@ discard block |
||
| 640 | 640 | return $this->config->get($taxKey, 0); |
| 641 | 641 | } |
| 642 | 642 | |
| 643 | - if (isset($this->postalCodeExceptions[$countryCode]) && $postalCode !== null) { |
|
| 644 | - foreach ($this->postalCodeExceptions[$countryCode] as $postalCodeException) { |
|
| 645 | - if (!preg_match($postalCodeException['postalCode'], $postalCode)) { |
|
| 643 | + if (isset($this->postalCodeExceptions[ $countryCode ]) && $postalCode !== null) { |
|
| 644 | + foreach ($this->postalCodeExceptions[ $countryCode ] as $postalCodeException) { |
|
| 645 | + if (!preg_match($postalCodeException[ 'postalCode' ], $postalCode)) { |
|
| 646 | 646 | continue; |
| 647 | 647 | } |
| 648 | - if (isset($postalCodeException['name'])) { |
|
| 649 | - return $this->taxRules[$postalCodeException['code']]['exceptions'][$postalCodeException['name']]; |
|
| 648 | + if (isset($postalCodeException[ 'name' ])) { |
|
| 649 | + return $this->taxRules[ $postalCodeException[ 'code' ] ][ 'exceptions' ][ $postalCodeException[ 'name' ] ]; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | - return $this->getRules($postalCodeException['code'], $date)['rate']; |
|
| 652 | + return $this->getRules($postalCodeException[ 'code' ], $date)[ 'rate' ]; |
|
| 653 | 653 | } |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | if ($type !== null) { |
| 657 | - return isset($this->taxRules[strtoupper($countryCode)]['rates'][$type]) ? $this->taxRules[strtoupper($countryCode)]['rates'][$type] : 0; |
|
| 657 | + return isset($this->taxRules[ strtoupper($countryCode) ][ 'rates' ][ $type ]) ? $this->taxRules[ strtoupper($countryCode) ][ 'rates' ][ $type ] : 0; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - return $this->getRules(strtoupper($countryCode), $date)['rate']; |
|
| 660 | + return $this->getRules(strtoupper($countryCode), $date)[ 'rate' ]; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | private function getRules($countryCode, $date): array |
| 664 | 664 | { |
| 665 | - if (!isset($this->taxRules[$countryCode])) { |
|
| 666 | - return ['rate' => 0]; |
|
| 665 | + if (!isset($this->taxRules[ $countryCode ])) { |
|
| 666 | + return [ 'rate' => 0 ]; |
|
| 667 | 667 | } |
| 668 | - if (isset($this->taxRules[$countryCode]['since'])) { |
|
| 669 | - foreach ($this->taxRules[$countryCode]['since'] as $since => $rates) { |
|
| 668 | + if (isset($this->taxRules[ $countryCode ][ 'since' ])) { |
|
| 669 | + foreach ($this->taxRules[ $countryCode ][ 'since' ] as $since => $rates) { |
|
| 670 | 670 | if (new \DateTimeImmutable($since) <= ($date !== null ? $date : $this->now)) { |
| 671 | 671 | return $rates; |
| 672 | 672 | } |
| 673 | 673 | } |
| 674 | 674 | } |
| 675 | - return $this->taxRules[$countryCode]; |
|
| 675 | + return $this->taxRules[ $countryCode ]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | /** |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | */ |
| 711 | 711 | public function getVATDetails($vatNumber) |
| 712 | 712 | { |
| 713 | - $vatNumber = str_replace([' ', "\xC2\xA0", "\xA0", '-', '.', ','], '', trim($vatNumber)); |
|
| 713 | + $vatNumber = str_replace([ ' ', "\xC2\xA0", "\xA0", '-', '.', ',' ], '', trim($vatNumber)); |
|
| 714 | 714 | $countryCode = substr($vatNumber, 0, 2); |
| 715 | 715 | $vatNumber = substr($vatNumber, 2); |
| 716 | 716 | $this->initSoapClient(); |