1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace Inspirum\Balikobot\Model\Branch; |
||
6 | |||
7 | use Inspirum\Balikobot\Definitions\Carrier; |
||
8 | use Inspirum\Balikobot\Definitions\Service; |
||
9 | use function in_array; |
||
10 | |||
11 | final class DefaultBranchResolver implements BranchResolver |
||
12 | { |
||
13 | 253 | public function hasFullBranchesSupport(string $carrier, ?string $service): bool |
|
14 | { |
||
15 | 253 | $supported = [ |
|
16 | 253 | Carrier::ZASILKOVNA => null, |
|
17 | 253 | Carrier::CP => [ |
|
18 | 253 | Service::CP_NP, |
|
19 | 253 | Service::CP_NB, |
|
20 | 253 | ], |
|
21 | 253 | Carrier::PBH => [ |
|
22 | 253 | Service::PBH_DHL, |
|
23 | 253 | Service::PBH_SPS, |
|
24 | 253 | Service::PBH_SP, |
|
25 | 253 | Service::PBH_MP, |
|
26 | 253 | Service::PBH_RP, |
|
27 | 253 | Service::PBH_CP_NP, |
|
28 | 253 | Service::PBH_INPOST_KURIER, |
|
29 | 253 | Service::PBH_FAN_KURIER, |
|
30 | 253 | Service::PBH_SPEEDY, |
|
31 | 253 | Service::PBH_ECONT, |
|
32 | 253 | Service::PBH_HR_POST, |
|
33 | 253 | Service::PBH_BOX_NOW, |
|
34 | 253 | Service::PBH_SI, |
|
35 | 253 | Service::PBH_ITELLA, |
|
36 | 253 | Service::PBH_CP_NB, |
|
37 | 253 | ], |
|
38 | 253 | Carrier::DPD => [ |
|
39 | 253 | Service::DPD_PICKUP, |
|
40 | 253 | ], |
|
41 | 253 | Carrier::GLS => [ |
|
42 | 253 | Service::GLS_SHOP, |
|
43 | 253 | Service::GLS_GUARANTEED24_SHOP, |
|
44 | 253 | ], |
|
45 | 253 | Carrier::INTIME => [ |
|
46 | 253 | Service::INTIME_POSTOMAT_CZ, |
|
47 | 253 | Service::INTIME_BOX_CZ, |
|
48 | 253 | Service::INTIME_BOX_SK, |
|
49 | 253 | ], |
|
50 | 253 | Carrier::SPS => [ |
|
51 | 253 | Service::SPS_EXPRESS, |
|
52 | 253 | Service::SPS_INTERNATIONAL, |
|
53 | 253 | ], |
|
54 | 253 | Carrier::SP => [ |
|
55 | 253 | Service::SP_BZP, |
|
56 | 253 | Service::SP_BZB, |
|
57 | 253 | Service::SP_EXP, |
|
58 | 253 | Service::SP_EXB, |
|
59 | 253 | Service::SP_BNP, |
|
60 | 253 | Service::SP_BNB, |
|
61 | 253 | ], |
|
62 | 253 | Carrier::ULOZENKA => [ |
|
63 | 253 | Service::ULOZENKA_ULOZENKA, |
|
64 | 253 | Service::ULOZENKA_DPD_PARCEL, |
|
65 | 253 | Service::ULOZENKA_CP_NP, |
|
66 | 253 | Service::ULOZENKA_PARTNER, |
|
67 | 253 | Service::ULOZENKA_EXPRESS_SK, |
|
68 | 253 | Service::ULOZENKA_BALIKOBOX_SK, |
|
69 | 253 | Service::ULOZENKA_DEPO_SK, |
|
70 | 253 | ], |
|
71 | 253 | Carrier::PPL => [ |
|
72 | 253 | Service::PPL_CONNECT, |
|
73 | 253 | Service::PPL_PRIVATE, |
|
74 | 253 | Service::PPL_PRIVATE_SMART_CZ, |
|
75 | 253 | Service::PPL_PRIVATE_SMART_EU, |
|
76 | 253 | ], |
|
77 | 253 | Carrier::SAMEDAY => [ |
|
78 | 253 | Service::SAMEDAY_LOCKER_NEXT_DAY, |
|
79 | 253 | Service::SAMEDAY_LOCKER_RETURN, |
|
80 | 253 | Service::SAMEDAY_CROSSBORDER_LOCKER_HD, |
|
81 | 253 | ], |
|
82 | 253 | Carrier::MAGYARPOSTA => null, |
|
83 | 253 | Carrier::RABEN => [ |
|
84 | 253 | Service::RABEN_CLASSIC_TIME, |
|
85 | 253 | Service::RABEN_PREMIUM_TIME, |
|
86 | 253 | ], |
|
87 | 253 | Carrier::DHLFREIGHTEC => [ |
|
88 | 253 | Service::DHLFREIGHTEC_ECD_B2B, |
|
89 | 253 | Service::DHLFREIGHTEC_ECD_B2C, |
|
90 | 253 | ], |
|
91 | 253 | Carrier::KURIER => [ |
|
92 | 253 | Service::KURIER_GARANTED, |
|
93 | 253 | Service::KURIER_GARANTED_BRANCH, |
|
94 | 253 | Service::KURIER_STANDARD, |
|
95 | 253 | Service::KURIER_STANDARD_BRANCH, |
|
96 | 253 | ], |
|
97 | 253 | Carrier::INPOST => null, |
|
98 | 253 | ]; |
|
99 | |||
100 | 253 | return $this->hasSupport($supported, $carrier, $service); |
|
101 | } |
||
102 | |||
103 | 247 | public function hasBranchCountryFilterSupport(string $carrier, ?string $service): bool |
|
104 | { |
||
105 | 247 | if ($service === null) { |
|
106 | 1 | return true; |
|
107 | } |
||
108 | |||
109 | 246 | $supported = [ |
|
110 | 246 | Carrier::PPL => null, |
|
111 | 246 | Carrier::DPD => null, |
|
112 | 246 | Carrier::GLS => null, |
|
113 | 246 | Carrier::ULOZENKA => null, |
|
114 | 246 | Carrier::PBH => [ |
|
115 | 246 | Service::PBH_DHL, |
|
116 | 246 | Service::PBH_CP_NP, |
|
117 | 246 | Service::PBH_SPS, |
|
118 | 246 | Service::PBH_SP, |
|
119 | 246 | Service::PBH_MP, |
|
120 | 246 | Service::PBH_RP, |
|
121 | 246 | Service::PBH_INPOST_KURIER, |
|
122 | 246 | Service::PBH_FAN_KURIER, |
|
123 | 246 | Service::PBH_SPEEDY, |
|
124 | 246 | Service::PBH_ECONT, |
|
125 | 246 | Service::PBH_HR_POST, |
|
126 | 246 | Service::PBH_BOX_NOW, |
|
127 | 246 | Service::PBH_SI, |
|
128 | 246 | Service::PBH_ITELLA, |
|
129 | 246 | Service::PBH_CP_NB, |
|
130 | 246 | ], |
|
131 | 246 | Carrier::SPS => null, |
|
132 | 246 | Carrier::RABEN => null, |
|
133 | 246 | Carrier::SAMEDAY => null, |
|
134 | 246 | Carrier::ZASILKOVNA => null, |
|
135 | 246 | Carrier::KURIER => null, |
|
136 | 246 | Carrier::MAGYARPOSTA => null, |
|
137 | 246 | ]; |
|
138 | |||
139 | 246 | return $this->hasSupport($supported, $carrier, $service); |
|
140 | } |
||
141 | |||
142 | /** |
||
143 | * @param array<string,list<string>|null> $supported |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
144 | */ |
||
145 | 499 | private function hasSupport(array $supported, string $carrier, ?string $service): bool |
|
146 | { |
||
147 | 499 | foreach ($supported as $supportedCarrier => $supportedServices) { |
|
148 | 499 | if ($carrier === $supportedCarrier && ($supportedServices === null || in_array($service, $supportedServices, true))) { |
|
149 | 210 | return true; |
|
150 | } |
||
151 | } |
||
152 | |||
153 | 290 | return false; |
|
154 | } |
||
155 | } |
||
156 |