Skip to content

Commit 089225e

Browse files
committed
deprecated helpers, use static classes instead
1 parent b8f3bc8 commit 089225e

File tree

4 files changed

+97
-3
lines changed

4 files changed

+97
-3
lines changed

src/Helpers/BusinessTypeFromNr.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace TantHammar\LaravelRules\Helpers;
4+
5+
use TantHammar\LaravelRules\Rules\OrgNummer;
6+
use TantHammar\LaravelRules\Rules\PersonNummer;
7+
8+
/** returns 'business', 'individual' or 'undefined' */
9+
class BusinessTypeFromNr
10+
{
11+
/** returns 'business', 'individual' or 'undefined' */
12+
public static function make(string|int $nr): string
13+
{
14+
if (filled($nr)) {
15+
if ((new PersonNummer())->passes(null, $nr)) {
16+
return 'individual';
17+
}
18+
if ((new OrgNummer())->passes(null, $nr)) {
19+
return 'business';
20+
}
21+
}
22+
return 'undefined';
23+
}
24+
}

src/RuleHelpers.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
class RuleHelpers
1010
{
11+
/**
12+
* @param string $vatID
13+
* @return string
14+
* @deprecated use BusinessNameFromVatID::lookup(string $vatID)
15+
*/
1116
public static function getBusinessNameFromVatID(string $vatID): string
1217
{
1318
try {
@@ -17,8 +22,10 @@ public static function getBusinessNameFromVatID(string $vatID): string
1722
}
1823
}
1924

20-
/** src https://github.com/driesvints/vat-calculator#get-eu-vat-number-details<br>
21-
* uk format: https://github.com/driesvints/vat-calculator#uk-vat-numbers
25+
/**
26+
* @param string $vatID
27+
* @return object
28+
* @deprecated use VatDetailsFromVatID::lookup(string $vatID)
2229
*/
2330
public static function getVATDetailsFromVatID(string $vatID): object
2431
{
@@ -37,7 +44,11 @@ public static function getVATDetailsFromVatID(string $vatID): object
3744
}
3845
}
3946

40-
/** returns 'business', 'individual' or 'undefined' */
47+
/**
48+
* @param string|int $nr
49+
* @return string
50+
* @deprecated use BusinessTypeFromNr::make(string|int $nr)
51+
*/
4152
public static function check_business_type(string|int $nr): string
4253
{
4354
if (filled($nr)) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace TantHammar\LaravelRules\Services;
4+
5+
use Mpociot\VatCalculator\Facades\VatCalculator;
6+
7+
class BusinessNameFromVatID
8+
{
9+
public static function lookup(string $vatID): string
10+
{
11+
$unknown = trans('laravel-rules::msg.vat-name-unknown');
12+
13+
if(!$vatID) {
14+
return $unknown;
15+
}
16+
17+
try {
18+
return VatCalculator::getVATDetails($vatID)?->name ?? $unknown;
19+
} catch (\Exception) {
20+
return $unknown;
21+
}
22+
23+
}
24+
}

src/Services/VatDetailsFromVatID.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace TantHammar\LaravelRules\Services;
4+
5+
use Mpociot\VatCalculator\Facades\VatCalculator;
6+
7+
/**
8+
* eu format or uk format:<br>
9+
* @see https://github.com/driesvints/vat-calculator#get-eu-vat-number-details
10+
* @see https://github.com/driesvints/vat-calculator#uk-vat-numbers
11+
*/
12+
class VatDetailsFromVatID
13+
{
14+
public static function lookup(string $vatID): object
15+
{
16+
$empty = new \stdClass([
17+
'countryCode' => '',
18+
'vatNumber' => '',
19+
'requestDate' => '',
20+
'valid' => false,
21+
'name' => '',
22+
'address' => '',
23+
]);
24+
25+
if(!$vatID) {
26+
return $empty;
27+
}
28+
29+
try {
30+
return VatCalculator::getVATDetails($vatID) ?? $empty;
31+
} catch (\Exception) {
32+
return $empty;
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)