Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"require-dev": {
"pestphp/pest": "^2.34",
"vlucas/phpdotenv": "^5.6"
"vlucas/phpdotenv": "^5.6",
"symfony/var-dumper": "^7.2"
},
"config": {
"allow-plugins": {
Expand Down
20 changes: 20 additions & 0 deletions src/Routing/DTO/Emission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PTV\Routing\DTO;

use PTV\Routing\Enums\EmissionType;

class Emission
{
public function __construct(
public readonly EmissionType $type,
public readonly ?float $fuelConsumption = null,
public readonly ?float $electricityConsumption = null,
public readonly ?float $co2eTankToWheel = null,
public readonly ?float $co2eWellToWheel = null,
public readonly ?float $energyUseTankToWheel = null,
public readonly ?float $energyUseWellToWheel = null,
)
{
}
}
2 changes: 2 additions & 0 deletions src/Routing/DTO/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PTV\Routing\DTO\Toll\Event;
use PTV\Routing\DTO\Toll\Toll;
use PTV\Routing\DTO\Emission;

class Route
{
Expand All @@ -15,6 +16,7 @@ public function __construct(
public readonly ?Toll $toll = null,
/** @var array<Event>|null */
public readonly ?array $events = null,
/** @var array<Emission>|null */
public readonly ?array $emissions = null,
/** @var array<Route>|null */
public readonly ?array $alternativeRoutes = null,
Expand Down
14 changes: 14 additions & 0 deletions src/Routing/Enums/EmissionType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace PTV\Routing\Enums;

enum EmissionType: string
{
case EN16258_2012 = 'en16258_2012';
case EN16258_2012_HBEFA = 'en16258_2012_hbefa';
case ISO14083_2022 = 'iso14083_2022';
case ISO14083_2022_DEFAULT_CONSUMPTION = 'iso14083_2022_default_consumption';
case ISO14083_2023 = 'iso14083_2023';
case ISO14083_2023_DEFAULT_CONSUMPTION = 'iso14083_2023_default_consumption';
case FRENCH_CO2E_DECREE_2017_639 = 'french_co2e_decree_2017_639';
}
21 changes: 20 additions & 1 deletion src/Routing/Requests/Routing/CreateRouteFromResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PTV\Data\DTO\TariffVersion;
use PTV\Data\DTO\TollSystem;
use PTV\Routing\DTO\Currencies;
use PTV\Routing\DTO\Emission;
use PTV\Routing\DTO\ExchangeRate;
use PTV\Routing\DTO\Leg;
use PTV\Routing\DTO\MonetaryCosts;
Expand All @@ -20,6 +21,7 @@
use PTV\Routing\DTO\Toll\Section;
use PTV\Routing\DTO\Toll\SectionCost;
use PTV\Routing\DTO\Toll\Toll;
use PTV\Routing\Enums\EmissionType;
use PTV\Routing\Enums\EtcSubscriptionType;
use PTV\Routing\Enums\PaymentMethod;

Expand All @@ -33,7 +35,7 @@ private function parseRoute(array $data): Route
legs: isset($data['legs']) ? array_map(fn(array $leg): Leg => $this->parseLeg($leg), $data['legs']) : null,
toll: isset($data['toll']) ? $this->parseToll($data) : null,
events: $data['events'] ?? null,
emissions: $data['emissions'] ?? null,
emissions: isset($data['emissions']) ? $this->parseEmissions($data['emissions']) : null,
alternativeRoutes: isset($data['alternativeRoutes']) ? array_map(fn(array $route): Route => $this->parseRoute($route), $data['alternativeRoutes']) : null,
scheduleReport: $data['scheduleReport'] ?? null,
evReport: $data['evReport'] ?? null,
Expand Down Expand Up @@ -166,4 +168,21 @@ private function parseTollCosts(array $costs): Cost
);
}

private function parseEmissions(array $emissions): array
{
foreach ($emissions as $type => $emission) {
$emissions[$type] = new Emission(
type: EmissionType::from($type),
fuelConsumption: $emission['fuelConsumption'] ?? null,
electricityConsumption: $emission['electricityConsumption'] ?? null,
co2eTankToWheel: $emission['co2eTankToWheel'] ?? null,
co2eWellToWheel: $emission['co2eWellToWheel'] ?? null,
energyUseTankToWheel: $emission['energyUseTankToWheel'] ?? null,
energyUseWellToWheel: $emission['energyUseWellToWheel'] ?? null,
);
}

return array_values($emissions);
}

}
1 change: 1 addition & 0 deletions tests/Feature/Routing/RoutingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
ResultType::TOLL_SECTIONS,
ResultType::TOLL_EVENTS,
ResultType::ALTERNATIVE_ROUTES,
ResultType::EMISSIONS_ISO14083_2023_DEFAULT_CONSUMPTION
// ResultType::GUIDED_NAVIGATION,
],
],
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading