-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddressFactory.php
More file actions
43 lines (37 loc) · 1.23 KB
/
AddressFactory.php
File metadata and controls
43 lines (37 loc) · 1.23 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
37
38
39
40
41
42
43
<?php
namespace DevMob\Postcodes\Providers\PostcodeApiNu;
use Adbar\Dot;
use DevMob\Postcodes\Traits\AccessesProperties;
class AddressFactory
{
use AccessesProperties;
/**
* Convert data to an address instance.
*
* @param array $data
* @return \DevMob\Postcodes\Providers\PostcodeApiNu\Address
*/
public function create(array $data): Address
{
$data = new Dot($data);
$location = $this->get($data, 'geo.center.wgs84.coordinates');
$houseNumber = $this->get($data, 'number') . $this->get($data, 'letter');
$address = new Address(
$this->get($data, 'postcode'),
$houseNumber,
$this->get($data, 'street'),
$this->get($data, 'city.label'),
$this->get($data, 'province.label'),
$location[1],
$location[0],
$data->all()
);
return $address
->withYear($this->get($data, 'year'))
->withLetter($this->get($data, 'letter'))
->withAddition($this->get($data, 'addition'))
->withSurface($this->get($data, 'surface'))
->withType($this->get($data, 'type'))
->withPurpose($this->get($data, 'purpose'));
}
}