@@ -51,7 +51,7 @@ |
||
| 51 | 51 | $valid_company = false; |
| 52 | 52 | if ($request->has('vat_number')) { |
| 53 | 53 | $valid_company = $this->validateVATID($request->get('vat_number')); |
| 54 | - $valid_company = $valid_company['is_valid']; |
|
| 54 | + $valid_company = $valid_company[ 'is_valid' ]; |
|
| 55 | 55 | $valid_vat_id = $valid_company; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -2,7 +2,6 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Mpociot\VatCalculator\Validators; |
| 4 | 4 | |
| 5 | -use Illuminate\Validation\Validator; |
|
| 6 | 5 | use Mpociot\VatCalculator\Exceptions\VATCheckUnavailableException; |
| 7 | 6 | use Mpociot\VatCalculator\Facades\VatCalculator; |
| 8 | 7 | |
@@ -9,7 +9,6 @@ |
||
| 9 | 9 | * @package Teamwork |
| 10 | 10 | */ |
| 11 | 11 | |
| 12 | -use Illuminate\Support\Facades\Validator; |
|
| 13 | 12 | use Illuminate\Support\ServiceProvider; |
| 14 | 13 | use Mpociot\VatCalculator\Facades\VatCalculator; |
| 15 | 14 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | { |
| 72 | 72 | $this->app->bind('vatcalculator', \Mpociot\VatCalculator\VatCalculator::class); |
| 73 | 73 | |
| 74 | - $this->app->bind(\Mpociot\VatCalculator\VatCalculator::class, function ($app) { |
|
| 74 | + $this->app->bind(\Mpociot\VatCalculator\VatCalculator::class, function($app) { |
|
| 75 | 75 | $config = $app->make('Illuminate\Contracts\Config\Repository'); |
| 76 | 76 | |
| 77 | 77 | return new \Mpociot\VatCalculator\VatCalculator($config); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | */ |
| 86 | 86 | public function registerFacade() |
| 87 | 87 | { |
| 88 | - $this->app->booting(function () { |
|
| 88 | + $this->app->booting(function() { |
|
| 89 | 89 | $loader = \Illuminate\Foundation\AliasLoader::getInstance(); |
| 90 | 90 | $loader->alias('VatCalculator', 'Mpociot\VatCalculator\Facades\VatCalculator'); |
| 91 | 91 | }); |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | 'vatnumber-validator' |
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | - $this->app['validator']->extend('vat_number', |
|
| 113 | + $this->app[ 'validator' ]->extend('vat_number', |
|
| 114 | 114 | 'Mpociot\VatCalculator\Validators\VatCalculatorValidatorExtension@validateVatNumber'); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -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(); |