|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Inspirum\Balikobot\Model\Factories; |
|
6
|
|
|
|
|
7
|
|
|
use Inspirum\Balikobot\Definitions\ServiceType; |
|
8
|
|
|
use Inspirum\Balikobot\Definitions\Shipper; |
|
9
|
|
|
use Inspirum\Balikobot\Model\Values\Branch; |
|
10
|
|
|
use function sprintf; |
|
11
|
|
|
use function trim; |
|
12
|
|
|
|
|
13
|
|
|
class BranchFactory |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* Create branch from API response data |
|
17
|
|
|
* |
|
18
|
|
|
* @param string $shipper |
|
19
|
|
|
* @param string|null $service |
|
20
|
|
|
* @param array<string,mixed> $data |
|
21
|
|
|
* |
|
22
|
|
|
* @return \Inspirum\Balikobot\Model\Values\Branch |
|
23
|
|
|
*/ |
|
24
|
20 |
|
public static function createFromData(string $shipper, ?string $service, array $data): Branch |
|
25
|
|
|
{ |
|
26
|
20 |
|
if ($shipper === Shipper::CP && $service === ServiceType::CP_NP) { |
|
27
|
10 |
|
$data['country'] ??= 'CZ'; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
20 |
|
if (isset($data['street']) && (isset($data['house_number']) || isset($data['orientation_number']))) { |
|
31
|
2 |
|
$houseNumber = (int) ($data['house_number'] ?? 0); |
|
32
|
2 |
|
$orientationNumber = (int) ($data['orientation_number'] ?? 0); |
|
33
|
2 |
|
$streetNumber = trim( |
|
34
|
2 |
|
sprintf( |
|
35
|
2 |
|
'%s/%s', |
|
36
|
2 |
|
$houseNumber > 0 ? $houseNumber : '', |
|
37
|
2 |
|
$orientationNumber > 0 ? $orientationNumber : '' |
|
38
|
|
|
), |
|
39
|
2 |
|
'/' |
|
40
|
|
|
); |
|
41
|
|
|
|
|
42
|
2 |
|
$data['street'] = trim(sprintf('%s %s', $data['street'] ?: ($data['city'] ?? ''), $streetNumber)); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
20 |
|
return new Branch( |
|
46
|
20 |
|
$shipper, |
|
47
|
|
|
$service, |
|
48
|
20 |
|
$data['branch_id'] ?? (isset($data['id']) ? (string) $data['id'] : null), |
|
49
|
20 |
|
$data['branch_uid'] ?? null, |
|
50
|
20 |
|
$data['type'] ?? 'branch', |
|
51
|
20 |
|
$data['name'] ?? ($data['zip'] ?? '00000'), |
|
52
|
20 |
|
$data['city'] ?? '', |
|
53
|
20 |
|
$data['street'] ?? ($data['address'] ?? ''), |
|
54
|
20 |
|
$data['zip'] ?? '00000', |
|
55
|
20 |
|
$data['country'] ?? null, |
|
56
|
20 |
|
$data['city_part'] ?? null, |
|
57
|
20 |
|
$data['district'] ?? null, |
|
58
|
20 |
|
$data['region'] ?? null, |
|
59
|
20 |
|
$data['currency'] ?? null, |
|
60
|
20 |
|
$data['photo_small'] ?? null, |
|
61
|
20 |
|
$data['photo_big'] ?? null, |
|
62
|
20 |
|
$data['url'] ?? null, |
|
63
|
20 |
|
(isset($data['latitude']) ? (float) trim((string) $data['latitude']) : null) ?: null, |
|
64
|
20 |
|
(isset($data['longitude']) ? (float) trim((string) $data['longitude']) : null) ?: null, |
|
65
|
20 |
|
$data['directions_global'] ?? null, |
|
66
|
20 |
|
$data['directions_car'] ?? null, |
|
67
|
20 |
|
$data['directions_public'] ?? null, |
|
68
|
20 |
|
isset($data['wheelchair_accessible']) ? (bool) $data['wheelchair_accessible'] : null, |
|
69
|
20 |
|
isset($data['claim_assistant']) ? (bool) $data['claim_assistant'] : null, |
|
70
|
20 |
|
isset($data['dressing_room']) ? (bool) $data['dressing_room'] : null, |
|
71
|
20 |
|
$data['opening_monday'] ?? null, |
|
72
|
20 |
|
$data['opening_tuesday'] ?? null, |
|
73
|
20 |
|
$data['opening_wednesday'] ?? null, |
|
74
|
20 |
|
$data['opening_thursday'] ?? null, |
|
75
|
20 |
|
$data['opening_friday'] ?? null, |
|
76
|
20 |
|
$data['opening_saturday'] ?? null, |
|
77
|
20 |
|
$data['opening_sunday'] ?? null, |
|
78
|
20 |
|
isset($data['max_weight']) ? (float) $data['max_weight'] : null |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|