refactor: delete the BusProNet base-data read path
This commit is contained in:
1 parent
0f76c5a7b6
commit
aa66c50979
4 files changed
+17
-168
No files matched your search
@@ -3,15 +3,11 @@
|
||||
namespace App\BusProNet;
|
||||
|
||||
use App\BusProNet\Model\Address;
|
||||
use App\BusProNet\Model\BaseDataResponse;
|
||||
use App\BusProNet\Model\Communication;
|
||||
use App\BusProNet\Model\Country;
|
||||
use App\BusProNet\Model\CrmAttribute;
|
||||
use App\BusProNet\Model\CrmAttributeGroup;
|
||||
use App\BusProNet\Model\CrmAttributesResponse;
|
||||
use App\BusProNet\Model\Hotel;
|
||||
use App\BusProNet\Model\NotificationResponse;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
use App\BusProNet\Model\ProfileResponse;
|
||||
use App\BusProNet\Model\ProfileUpdateResponse;
|
||||
use App\BusProNet\Model\RegistrationResponse;
|
||||
@@ -64,12 +60,6 @@ class ResponseParser
|
||||
return $this->createRegistrationResponse($xml);
|
||||
}
|
||||
break;
|
||||
case ApiClient::TYPE_BASE_DATA_COUNTRIES:
|
||||
return $this->createCountriesResponse($xml);
|
||||
case ApiClient::TYPE_BASE_DATA_PICKUPS:
|
||||
return $this->createPickupsResponse($xml);
|
||||
case ApiClient::TYPE_BASE_DATA_HOTELS:
|
||||
return $this->createHotelsResponse($xml);
|
||||
}
|
||||
|
||||
throw new ResponseParserException(sprintf('Unrecognised BusProNet response type "%s"', $responseType));
|
||||
@@ -268,75 +258,6 @@ class ResponseParser
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function createCountriesResponse(\SimpleXMLElement $xml): BaseDataResponse
|
||||
{
|
||||
$countries = [];
|
||||
|
||||
foreach ($xml->laender->land as $item) {
|
||||
$itemAttributes = $item->attributes();
|
||||
$token = (string) $itemAttributes['kuerzel'];
|
||||
$country = new Country();
|
||||
$country
|
||||
->setId((int) $itemAttributes['id'])
|
||||
->setName((string) $itemAttributes['bezeichnung'])
|
||||
->setToken((string) $itemAttributes['kuerzel'])
|
||||
->setNationality((string) $itemAttributes['nationalitaet'])
|
||||
;
|
||||
$countries[$token] = $country;
|
||||
}
|
||||
|
||||
return new BaseDataResponse($countries);
|
||||
}
|
||||
|
||||
public function createPickupsResponse(\SimpleXMLElement $xml): BaseDataResponse
|
||||
{
|
||||
$pickups = [];
|
||||
|
||||
foreach ($xml->zustieg as $item) {
|
||||
$itemAttributes = $item->attributes();
|
||||
$id = (int) $itemAttributes['id'];
|
||||
$busProId = (int) $itemAttributes['idbuspro'];
|
||||
$pickup = new Pickup();
|
||||
$pickup
|
||||
->setId($id)
|
||||
->setBusProId($busProId)
|
||||
->setCode((string) $itemAttributes['code'])
|
||||
->setCity((string) $item->ort)
|
||||
->setStreet((string) $item->strasse)
|
||||
;
|
||||
$pickups[$busProId] = $pickup;
|
||||
}
|
||||
|
||||
return new BaseDataResponse($pickups);
|
||||
}
|
||||
|
||||
public function createHotelsResponse(\SimpleXMLElement $xml): BaseDataResponse
|
||||
{
|
||||
$hotels = [];
|
||||
|
||||
foreach ($xml->hotel as $item) {
|
||||
$itemAttributes = $item->attributes();
|
||||
$id = (int) $itemAttributes['id'];
|
||||
$busProId = (int) $itemAttributes['idbuspro'];
|
||||
$hotel = new Hotel();
|
||||
$hotel
|
||||
->setId($id)
|
||||
->setBusProId($busProId)
|
||||
->setCode((string) $itemAttributes['code'])
|
||||
->setName((string) $item->name)
|
||||
->setCountry(strtolower((string) $item->land))
|
||||
->setCity((string) $item->ort)
|
||||
->setStreet((string) $item->strasse)
|
||||
->setPhone((string) $item->telefon)
|
||||
->setType((string) $item->art)
|
||||
->setCostUnit($item->kostenstelle)
|
||||
;
|
||||
$hotels[$busProId] = $hotel;
|
||||
}
|
||||
|
||||
return new BaseDataResponse($hotels);
|
||||
}
|
||||
|
||||
/**
|
||||
* The BusProNet endpoint can answer with an empty or truncated body. Keep the libxml
|
||||
* reason instead of collapsing every shape of broken response into one message.
|
||||
|
||||
Reference in new issue
Block a user