Skip to content

Commit

Permalink
Merge branch 'main' into feat/create-token-command
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarchois authored Jan 22, 2025
2 parents b7120e7 + 69e2b9b commit e35ec43
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/Infrastructure/Litteralis/LitteralisRecordEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ enum LitteralisRecordEnum: string
case COUNT_EXTRACTED_FEATURES = 'litteralis.extracted_features';
case COUNT_IMPORTED_FEATURES = 'litteralis.imported_features';

case ERROR_MEASURE_PARAMETER_MALFORMED = 'litteralis.measure_parameter_malformed';
case ERROR_MEASURE_PARAMETER_INCONSISTENT_NUMBER = 'litteralis.measure_parameter_inconsistent_number';
case ERROR_MAX_SPEED_VALUE_INVALID = 'litteralis.max_speed_value_invalid';
case ERROR_MAX_SPEED_VALUE_MISSING = 'litteralis.max_speed_value_missing';
Expand Down
21 changes: 18 additions & 3 deletions src/Infrastructure/Litteralis/LitteralisTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ public function transform(
private function setCategory(SaveRegulationGeneralInfoCommand $generalInfoCommand, array $properties): void
{
$generalInfoCommand->category = $properties['documenttype'] === 'ARRETE PERMANENT'
? RegulationOrderCategoryEnum::PERMANENT_REGULATION->value
: RegulationOrderCategoryEnum::TEMPORARY_REGULATION->value;
? RegulationOrderCategoryEnum::PERMANENT_REGULATION->value
: RegulationOrderCategoryEnum::TEMPORARY_REGULATION->value;
}

private function setSubject(SaveRegulationGeneralInfoCommand $generalInfoCommand, array $properties): void
Expand Down Expand Up @@ -277,7 +277,22 @@ private function gatherMeasureParameters(array $properties, Reporter $reporter):

foreach ($measureParameters as $param) {
// Exemple : "Circulation interdite 2 | dérogation : urgences" -> ['Circulation interdite 2', 'dérogation : urgences']
[$name, $item] = $this->parseSeparatedString($param, '|');
$parts = explode('|', $param, 2);

if (\count($parts) !== 2) {
$reporter->addError(LitteralisRecordEnum::ERROR_MEASURE_PARAMETER_MALFORMED->value, [
CommonRecordEnum::ATTR_REGULATION_ID->value => $properties['arretesrcid'],
CommonRecordEnum::ATTR_URL->value => $properties['shorturl'],
CommonRecordEnum::ATTR_DETAILS->value => [
'idemprise' => $properties['idemprise'],
'param' => $param,
],
]);

continue;
}

[$name, $item] = array_map(fn ($s) => trim($s), $parts);

if (preg_match('/^(?P<name>[\s|\w]+) (?P<number>\d+)$/i', $name, $matches)) {
// Si un numéro est indiqué, il doit correspondre au index commençant à 1 de la mesure dans le champ 'mesures'.
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Infrastructure/Litteralis/LitteralisTransformerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ public function testTransformWithErrors(): void
self::feature,
);

// Trigger ERROR_MEASURE_PARAMETER_MALFORMED
$malformedParamFeature = str_replace(
'"mesures": "Limitation de vitesse"',
'"mesures": "Circulation interdite"',
self::feature,
);
$malformedParamFeature = str_replace(
'"parametresmesures": "Limitation de vitesse | limite de vitesse : 70 km/h"',
'"parametresmesures": "Circulation interdite 1"',
$malformedParamFeature,
);

// Trigger ERROR_MEASURE_PARAMETER_INCONSISTENT_NUMBER
$inconsistentIndexFeature = str_replace(
'"mesures": "Limitation de vitesse"',
Expand All @@ -273,6 +285,7 @@ public function testTransformWithErrors(): void
json_decode($invalidDatesFeature, associative: true),
json_decode($missingSpeedLimitValueFeature, associative: true),
json_decode($invalidSpeedLimitValueFeature, associative: true),
json_decode($malformedParamFeature, associative: true),
json_decode($inconsistentIndexFeature, associative: true),
json_decode($periodUnparsableFeature, associative: true),
];
Expand Down Expand Up @@ -331,6 +344,18 @@ public function testTransformWithErrors(): void
],
],
],
[
RecordTypeEnum::ERROR->value,
[
RecordTypeEnum::ERROR->value => LitteralisRecordEnum::ERROR_MEASURE_PARAMETER_MALFORMED->value,
CommonRecordEnum::ATTR_REGULATION_ID->value => '24-A-0126',
CommonRecordEnum::ATTR_URL->value => 'https://dl.sogelink.fr/?n3omzTyS',
CommonRecordEnum::ATTR_DETAILS->value => [
'idemprise' => 493136,
'param' => 'Circulation interdite 1',
],
],
],
[
RecordTypeEnum::ERROR->value,
[
Expand Down
4 changes: 4 additions & 0 deletions translations/messages.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -2491,6 +2491,10 @@
<source>integration.report.error.litteralis.period_unparsable</source>
<target>Emprises avec "jours et horaires" au format non-supporté</target>
</trans-unit>
<trans-unit id="integration.report.error.litteralis.measure_parameter_malformed">
<source>integration.report.error.litteralis.measure_parameter_malformed</source>
<target>Emprises avec paramètres de mesures au format inattendu</target>
</trans-unit>
<trans-unit id="integration.report.error.litteralis.measure_parameter_inconsistent_number">
<source>integration.report.error.litteralis.measure_parameter_inconsistent_number</source>
<target>Emprises avec numéros de mesures incohérents</target>
Expand Down

0 comments on commit e35ec43

Please sign in to comment.