Skip to content

Commit aca82c7

Browse files
author
Quentin Bontemps
committed
update search version & fixe extract result data
1 parent 5eb69bc commit aca82c7

File tree

3 files changed

+50
-17
lines changed

3 files changed

+50
-17
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"email": "q.bontemps@gmail.com"
1313
}
1414
],
15-
"version": "1.0.0",
15+
"version": "1.0.1",
1616
"require-dev": {
1717
"phpunit/phpunit": "^5.0"
1818
},

src/MondialRelay/ApiClient.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ public function findDeliveryPoints(array $request)
2424
{
2525
try {
2626
$request = $this->decorateRequest($request);
27-
$result = $this->client->WSI3_PointRelais_Recherche($request);
27+
$result = $this->client->WSI4_PointRelais_Recherche($request);
2828
$pointFactory = new PointFactory();
29-
$this->checkResponse('WSI3_PointRelais_Recherche', $result);
29+
$this->checkResponse('WSI4_PointRelais_Recherche', $result);
3030
$delivery_points = [];
31-
if (!property_exists($result->WSI3_PointRelais_RechercheResult->PointsRelais, 'PointRelais_Details')) {
31+
if (!property_exists($result->WSI4_PointRelais_RechercheResult->PointsRelais, 'PointRelais_Details')) {
3232
return $delivery_points;
3333
}
34-
if (is_object($result->WSI3_PointRelais_RechercheResult->PointsRelais->PointRelais_Details)) {
35-
$delivery_points[] = $pointFactory->create($result->WSI3_PointRelais_RechercheResult->PointsRelais->PointRelais_Details);
34+
if (is_object($result->WSI4_PointRelais_RechercheResult->PointsRelais->PointRelais_Details)) {
35+
$delivery_points[] = $pointFactory->create($result->WSI4_PointRelais_RechercheResult->PointsRelais->PointRelais_Details);
3636
return $delivery_points;
3737
}
38-
foreach ($result->WSI3_PointRelais_RechercheResult->PointsRelais->PointRelais_Details as $destination_point) {
38+
foreach ($result->WSI4_PointRelais_RechercheResult->PointsRelais->PointRelais_Details as $destination_point) {
3939
$delivery_points[] = $pointFactory->create($destination_point);
4040
}
4141
return $delivery_points;

src/MondialRelay/Point/PointFactory.php

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,63 @@
1212
*/
1313
class PointFactory
1414
{
15+
1516
public function create($response)
1617
{
1718
$bussines_hours = (new BussinessHoursFactory())->create($response);
19+
1820
return new Point(
1921
$response->Num,
2022
str_replace(",", ".", $response->Latitude),
2123
str_replace(",", ".", $response->Longitude),
2224
$response->CP,
23-
[
24-
trim($response->LgAdr1),
25-
trim($response->LgAdr2),
26-
trim($response->LgAdr3),
27-
trim($response->LgAdr4)
28-
],
25+
$this->extractAddress($response),
2926
$response->Ville,
3027
$response->Pays,
31-
[
32-
$response->Localisation1,
33-
$response->Localisation2
34-
],
28+
$this->extractLocalisation($response),
3529
$response->TypeActivite,
3630
$response->Information,
3731
$bussines_hours
3832
);
33+
}
34+
35+
protected function extractAddress($response)
36+
{
37+
$address = [];
38+
$attributes = [
39+
'LgAdr1',
40+
'LgAdr2',
41+
'LgAdr3',
42+
'LgAdr4',
43+
];
44+
45+
foreach ($attributes as $attribute)
46+
{
47+
if (property_exists($response, $attribute))
48+
{
49+
$address[] = trim($response->{$attribute});
50+
}
51+
}
52+
53+
return $address;
54+
}
55+
56+
protected function extractLocalisation($response)
57+
{
58+
$localisation = [];
59+
$attributes = [
60+
'Localisation1',
61+
'Localisation2',
62+
];
63+
64+
foreach ($attributes as $attribute)
65+
{
66+
if (property_exists($response, $attribute))
67+
{
68+
$localisation[] = trim($response->{$attribute});
69+
}
70+
}
3971

72+
return $address;
4073
}
4174
}

0 commit comments

Comments
 (0)