-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnergyLabelCollectionFactory.php
More file actions
60 lines (54 loc) · 2.16 KB
/
EnergyLabelCollectionFactory.php
File metadata and controls
60 lines (54 loc) · 2.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Label84\NederlandPostcode\Factories;
use DateTime;
use Label84\NederlandPostcode\DTO\EnergyLabel;
use Label84\NederlandPostcode\DTO\EnergyLabelCollection;
class EnergyLabelCollectionFactory
{
/**
* @param array{data: array{
* postcode: string,
* number: int,
* addition?: string|null,
* street: string,
* city: string,
* energy_labels: array<array{
* inspection_date: string,
* valid_until_date: string,
* construction_type: string,
* building_type: string|null,
* energy_label: string,
* max_energy_demand: float,
* max_fossil_energy_demand: float,
* min_renewable_share: float,
* }>,
* }} $response
*/
public static function make(array $response): EnergyLabelCollection
{
$postcode = $response['data']['postcode'];
$number = $response['data']['number'];
$addition = $response['data']['addition'] ?? null;
$street = $response['data']['street'];
$city = $response['data']['city'];
$energyLabels = array_map(function (array $attributes) use ($postcode, $number, $addition, $street, $city) {
return new EnergyLabel(
postcode: $postcode,
number: $number,
addition: $addition,
street: $street,
city: $city,
inspectionDate: new DateTime($attributes['inspection_date']),
validUntilDate: new DateTime($attributes['valid_until_date']),
constructionType: $attributes['construction_type'],
buildingType: $attributes['building_type'],
energyLabel: $attributes['energy_label'],
maxEnergyDemand: $attributes['max_energy_demand'],
maxFossilEnergyDemand: $attributes['max_fossil_energy_demand'],
minRenewableShare: $attributes['min_renewable_share'],
);
}, $response['data']['energy_labels']);
$energyLabels = array_values($energyLabels);
return new EnergyLabelCollection($energyLabels);
}
}