Skip to content

Commit bd7d961

Browse files
committed
Fix standard en_GB VAT numbers being generated with an incorrect number of digits
Standard UK VAT numbers should be 9 digits. If the Modulus 97 block of a UK VAT number has a leading 0, this zero gets thrown out when sprintf casts this block from a string (%s) to an int (%d) during formatting. For example, a check block of "07" would end up like: GB216 5727 7 but it should be: GB216 5727 07
1 parent c5c3935 commit bd7d961

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Removed functionality for populating ORM entities and models (#764)
88
- Added a PHP version support policy (#752)
99
- Stopped using `static` in callables in `Provider\pt_BR\PhoneNumber` (#785)
10+
- Fixed en_GB standard VAT numbers (#969)
1011

1112
## [2023-06-12, v1.23.0](https://github.com/FakerPHP/Faker/compare/v1.22.0..v1.23.0)
1213

src/Provider/en_GB/Company.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static function generateStandardVatNumber(): string
4949
$secondBlock = static::randomNumber(4, true);
5050

5151
return sprintf(
52-
'%s%d %d %d',
52+
'%s%s %s %s',
5353
static::VAT_PREFIX,
5454
$firstBlock,
5555
$secondBlock,
@@ -64,7 +64,7 @@ private static function generateStandardVatNumber(): string
6464
private static function generateHealthAuthorityVatNumber(): string
6565
{
6666
return sprintf(
67-
'%sHA%d',
67+
'%sHA%s',
6868
static::VAT_PREFIX,
6969
static::numberBetween(500, 999),
7070
);
@@ -77,7 +77,7 @@ private static function generateHealthAuthorityVatNumber(): string
7777
private static function generateBranchTraderVatNumber(): string
7878
{
7979
return sprintf(
80-
'%s %d',
80+
'%s %s',
8181
static::generateStandardVatNumber(),
8282
static::randomNumber(3, true),
8383
);

test/Provider/en_GB/CompanyTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ public function testVatHealthAuthorityType(): void
6262
self::assertTrue($matches[1] < 1000);
6363
}
6464

65+
public function testLeadingZeroInModulus97BlockRemainsAfterFormatting(): void
66+
{
67+
// Force Faker to generate VAT number GB216 5727 07
68+
$this->faker->seed(297957);
69+
$number = $this->faker->vat();
70+
$this->assertDefaultVatFormat($number);
71+
self::assertStringEndsWith('07', substr($number, -2));
72+
}
73+
6574
protected function getProviders(): iterable
6675
{
6776
yield new Company($this->faker);

0 commit comments

Comments
 (0)