feat: make boarding point price levelling switchable

This commit is contained in:
fromme committed 2026-09-29 10:11:03 +02:00
1 parent 0c6126010f
commit f5e6d2105d
8 files changed
+92 -13

No files matched your search

@@ -8,6 +8,11 @@ use App\BusProNet\XmlCrawlerFactory;
class ApiResponseParser extends AbstractParser
{
public function __construct(
private readonly TravelParser $travelParser,
) {
}
/**
* @throws ResponseParserException
*/
@@ -81,7 +86,7 @@ class ApiResponseParser extends AbstractParser
throw new ResponseParserException('No travel data node found in product data response');
}
return (new TravelParser())->parse($travelNode->first(), ...$additionalArgs);
return $this->travelParser->parse($travelNode->first(), ...$additionalArgs);
case ApiClient::TYPE_AGENCIES:
return (new AgencyParser())->parse($resultNode);
case ApiClient::TYPE_PURCHASE_VOUCHER:
+22 -3
View File
@@ -29,8 +29,20 @@ class TravelParser extends AbstractParser
Constants::PSEUDO_PRICE_ROOM_CODE,
];
/**
* `$levelBoardingPointPrices` carries no default on purpose: a hand-built parser would
* otherwise silently ignore APP_BPN_LEVEL_BOARDING_POINT_PRICES and price one travel tier
* differently from the others. The registry gave up its own default along with it, so that
* there is one way to build this class — through the container, or explicitly in a test.
*
* @param bool $levelBoardingPointPrices Whether to compensate the BusPro export defect that
* omits a boarding point's return-leg price. The
* container wires it from
* APP_BPN_LEVEL_BOARDING_POINT_PRICES.
*/
public function __construct(
private readonly AgeConstraintParserRegistry $ageConstraintRegistry = new AgeConstraintParserRegistry(),
private readonly AgeConstraintParserRegistry $ageConstraintRegistry,
private readonly bool $levelBoardingPointPrices,
) {
}
@@ -88,7 +100,9 @@ class TravelParser extends AbstractParser
$travel->dropOffs = $this->getPickups($node->filterXPath('.//zustiege_rueck/zustieg_rueck'), $dateTo, false);
// A boarding point costs the same in both directions
$this->levelBoardingPointPrices($travel->pickups, $travel->dropOffs);
if ($this->levelBoardingPointPrices) {
$this->applyBoardingPointPriceLevelling($travel->pickups, $travel->dropOffs);
}
$travel->guide = $this->getGuide($node);
@@ -465,10 +479,15 @@ class TravelParser extends AbstractParser
* Where both directions state a price they agree in practice; the outbound one wins
* to keep the outcome deterministic. Points without a counterpart are left as they are.
*
* Compensating the defect locally is provisional, so it is switchable: with
* `$levelBoardingPointPrices` off the export is reported verbatim and the affected
* travels undercharge the return leg again. See
* `docs/buspro-database-reference.md` section A7.
*
* @param array<int, Pickup> $pickups Pickups indexed by ID (modified in place)
* @param array<int, Pickup> $dropOffs Drop-offs indexed by ID (modified in place)
*/
private function levelBoardingPointPrices(array &$pickups, array $dropOffs): void
private function applyBoardingPointPriceLevelling(array $pickups, array $dropOffs): void
{
foreach ($dropOffs as $pickupId => $dropOff) {
if (false === isset($pickups[$pickupId])) {