Skip to content

Commit

Permalink
Add method to check if country is supported, add doccomments for bett…
Browse files Browse the repository at this point in the history
…er IDE support

Signed-off-by: Tobias Oitzinger <tobiasoitzinger@gmail.com>
  • Loading branch information
toitzi authored and danielebarbaro committed Jan 4, 2024
1 parent c63b8d6 commit 3190e74
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Facades/VatValidatorFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@
use Danielebarbaro\LaravelVatEuValidator\VatValidator;
use Illuminate\Support\Facades\Facade;

/**
* @method bool validateFormat(string $vatNumber)
* @method bool validateExistence(string $vatNumber)
* @method bool validate(string $vatNumber)
* @method static int luhnCheck(string $vatNumber)
* @method static string countryIsSupported(string $country)
*/
class VatValidatorFacade extends Facade
{
/**
Expand Down
9 changes: 9 additions & 0 deletions src/VatValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ public function __construct(Client $client = null)
}
}

/**
* Return if a country is supported by this validator
* @param string $country
* @return bool
*/
public static function countryIsSupported(string $country): bool {
return isset(self::$pattern_expression[$country]);
}

/**
* Validate a VAT number format.
* @param string $vatNumber
Expand Down
19 changes: 19 additions & 0 deletions tests/Rules/CountryIsSupportedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Danielebarbaro\LaravelVatEuValidator\Tests\Rules;

use Danielebarbaro\LaravelVatEuValidator\VatValidator;
use Orchestra\Testbench\TestCase;

class CountryIsSupportedTest extends TestCase
{
public function testCountryIsSupported()
{
self::assertTrue(VatValidator::countryIsSupported('AT'));
}

public function testCountryIsNotSupported()
{
self::assertFalse(VatValidator::countryIsSupported('US'));
}
}

0 comments on commit 3190e74

Please sign in to comment.