-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from sandervankasteel/feature/GbVatNumber
Added basic GB VAT number validation
- Loading branch information
Showing
14 changed files
with
98 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
FROM php:8.0-alpine | ||
FROM php:8.1-alpine | ||
|
||
RUN apk update && \ | ||
apk add composer \ | ||
bash \ | ||
php8-dom \ | ||
php8-tokenizer \ | ||
php8-fileinfo \ | ||
php8-xml \ | ||
php8-xmlwriter \ | ||
php8-pecl-xdebug | ||
php81-bcmath \ | ||
php81-dom \ | ||
php81-tokenizer \ | ||
php81-fileinfo \ | ||
php81-xml \ | ||
php81-xmlwriter \ | ||
php81-pecl-xdebug | ||
|
||
RUN docker-php-ext-install bcmath | ||
RUN docker-php-ext-install bcmath && docker-php-ext-enable bcmath | ||
|
||
ENTRYPOINT ["tail"] | ||
CMD ["-f","/dev/null"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# VatNumber | ||
### `LaravelExtendedValidation\Rules\Locale\GB\Company\VatNumber` | ||
|
||
Determines if the supplied VAT number is a valid British VAT number. | ||
|
||
A valid examples are `GB123456789` or `GB123456789012`. They have to start with GB and be either 9 or 12 characters in length. | ||
|
||
## Constructor argument(s) | ||
|
||
```php | ||
none | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace LaravelExtendedValidation\Rules\Locale\GB\Company; | ||
|
||
use Illuminate\Contracts\Validation\Rule; | ||
use Illuminate\Support\Str; | ||
|
||
class VatNumber implements Rule | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function passes($attribute, $value): bool | ||
{ | ||
/** @var string $numbers */ | ||
$numbers = Str::of($value) | ||
->replace(' ', '') | ||
->upper() | ||
->split('/GB/') | ||
->filter() | ||
->first(); | ||
|
||
if (! Str::of($value)->upper()->startsWith('GB')) { | ||
return false; | ||
} | ||
|
||
if (Str::of($numbers)->length() !== 9 && Str::of($numbers)->length() !== 12) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function message(): string | ||
{ | ||
return ':attribute does not contain a valid British VAT number'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
use LaravelExtendedValidation\Rules\Locale\GB\Company\VatNumber; | ||
|
||
test('that we can successfully validate VAT numbers', function ($vatNumber, $expectedOutput) { | ||
$sut = new VatNumber(); | ||
|
||
expect( | ||
$sut->passes('some-attribute', $vatNumber) | ||
)->toBe($expectedOutput); | ||
})->with([ | ||
['GB123456789', true], | ||
['GB123456789012', true], | ||
['GB1234567890', false], | ||
['GB12345678', false], | ||
['FR3285520050', false], | ||
]); | ||
|
||
test('that we get the attribute back from the error message', function () { | ||
$sut = new VatNumber(); | ||
expect( | ||
$sut->message() | ||
)->toContain(':attribute'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ | |
|
||
uses(TestCase::class) | ||
->beforeEach(function () { | ||
|
||
/** @var $app Application */ | ||
$app = $this->app; | ||
|
||
|