-
Notifications
You must be signed in to change notification settings - Fork 473
Expand file tree
/
Copy pathTestCustomPostcodeResolver.php
More file actions
36 lines (30 loc) · 1.04 KB
/
TestCustomPostcodeResolver.php
File metadata and controls
36 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Lunar\Tests\Shipping\Stubs\Resolvers;
use Illuminate\Support\Collection;
use Lunar\Models\Contracts\Country as CountryContract;
use Lunar\Shipping\Interfaces\PostcodeResolverInterface;
class TestCustomPostcodeResolver implements PostcodeResolverInterface
{
/**
* ISO-2 codes this test resolver claims. Override via subclass if you need a different set.
*
* @var array<int, string>
*/
protected array $countries = [];
public function supportsCountry(CountryContract $country): bool
{
return empty($this->countries)
|| in_array($country->iso2, $this->countries, true);
}
public function getParts(string $postcode, CountryContract $country): Collection
{
$postcode = str_replace(' ', '', strtoupper($postcode));
return collect([
$postcode,
substr($postcode, 0, 1).'*',
substr($postcode, 0, 2).'*',
substr($postcode, 0, 3).'*',
substr($postcode, 0, 4).'*',
])->filter()->unique()->values();
}
}