Skip to content

Commit

Permalink
Codestyle
Browse files Browse the repository at this point in the history
  • Loading branch information
JoryHogeveen committed Dec 21, 2023
1 parent e623ea9 commit 0af9b85
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions vatchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ class Vatchecker extends Module
* @var string[]
*/
private $euVatFormats = [
'AT' => '(AT)?U[0-9]{8}', # Austria
'BE' => '(BE)?0[0-9]{9}', # Belgium
'BG' => '(BG)?[0-9]{9,10}', # Bulgaria
'CY' => '(CY)?[0-9]{8}[A-Z]', # Cyprus
'CZ' => '(CZ)?[0-9]{8,10}', # Czech Republic
'DE' => '(DE)?[0-9]{9}', # Germany
'DK' => '(DK)?[0-9]{8}', # Denmark
'EE' => '(EE)?[0-9]{9}', # Estonia
'GR' => '(EL)?[0-9]{9}', # Greece
'ES' => '(ES)?[A-Z][0-9]{7}(?:[0-9]|[A-Z])', # Spain
'FI' => '(FI)?[0-9]{8}', # Finland
'FR' => '(FR)?[0-9A-Z]{2}[0-9]{9}', # France
'AT' => '(AT)?U[0-9]{8}', # Austria
'BE' => '(BE)?0[0-9]{9}', # Belgium
'BG' => '(BG)?[0-9]{9,10}', # Bulgaria
'CY' => '(CY)?[0-9]{8}[A-Z]', # Cyprus
'CZ' => '(CZ)?[0-9]{8,10}', # Czech Republic
'DE' => '(DE)?[0-9]{9}', # Germany
'DK' => '(DK)?[0-9]{8}', # Denmark
'EE' => '(EE)?[0-9]{9}', # Estonia
'GR' => '(EL)?[0-9]{9}', # Greece
'ES' => '(ES)?[A-Z][0-9]{7}(?:[0-9]|[A-Z])', # Spain
'FI' => '(FI)?[0-9]{8}', # Finland
'FR' => '(FR)?[0-9A-Z]{2}[0-9]{9}', # France
//'GB' => '(GB)?([0-9]{9}([0-9]{3})?|[A-Z]{2}[0-9]{3})', # United Kingdom // Brexit!
'HR' => '(HR)?[0-9]{11}', # Croatia
'HU' => '(HU)?[0-9]{8}', # Hungary
Expand Down Expand Up @@ -661,9 +661,11 @@ private function setVatValidation( $record )
$table = _DB_PREFIX_ . 'vatchecker';

// Required fields.
if ( empty( $record['id_address'] )
|| empty( $record['id_country'] )
|| empty( $record['vat_number'] ) ) {
if (
empty( $record['id_address'] ) ||
empty( $record['id_country'] ) ||
empty( $record['vat_number'] )
) {
return false;
}

Expand All @@ -674,7 +676,8 @@ private function setVatValidation( $record )
}
}

$today = date( 'Y-m-d H:i:s' );
$today = date( 'Y-m-d H:i:s' );

$record['date_modified'] = $today;
if ( $record['valid'] ) {
$record['date_valid_vat'] = $today;
Expand Down Expand Up @@ -749,14 +752,16 @@ public function checkVat( $vatNumber, $countryCode )
}

if ( ! $countryCode || ! $this->isEUCountry( $countryCode ) ) {
$return['error'] = $this->l( 'Please select an EU country' );
$return['error'] = $this->l( 'Please select an EU country' );

self::$cache[ $cache_key ] = $return;

return $return;
}

if ( ! $vatNumber ) {
$return['error'] = $this->l( 'Please provide a VAT number' );
$return['error'] = $this->l( 'Please provide a VAT number' );

self::$cache[ $cache_key ] = $return;

return $return;
Expand All @@ -765,7 +770,8 @@ public function checkVat( $vatNumber, $countryCode )
$vatNumber = ltrim( $vatNumber, $countryCode );

if ( ! $this->isVatFormat( $vatNumber ) ) {
$return['error'] = $this->l( 'VAT number format invalid' );
$return['error'] = $this->l( 'VAT number format invalid' );

self::$cache[ $cache_key ] = $return;

return $return;
Expand Down Expand Up @@ -962,7 +968,7 @@ public function getEUCountries( $cache = true )
if ( $cache && $countries ) {
return $countries;
}
$all_countries = Country::getCountries( $this->context->language->id,0 );
$all_countries = Country::getCountries( $this->context->language->id );
$countries = [];
foreach ( $all_countries as $country ) {
if ( array_key_exists( $country['iso_code'], $this->euVatFormats ) ) {
Expand Down

0 comments on commit 0af9b85

Please sign in to comment.