-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RD/RN : Détecte le côté à partir du sens concerné
- Loading branch information
1 parent
cafbb7f
commit 99ecb30
Showing
11 changed files
with
203 additions
and
52 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/Application/Exception/BothDirectionsNotSupportedAtPointNumbers.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application\Exception; | ||
|
||
class BothDirectionsNotSupportedAtPointNumbers extends GeocodingFailureException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Application; | ||
|
||
interface PointNumberSideDetectorInterface | ||
{ | ||
public function detect( | ||
string $direction, | ||
string $administrator, | ||
string $roadNumber, | ||
string $fromPointNumber, | ||
int $fromAbscissa, | ||
string $toPointNumber, | ||
int $toAbscissa, | ||
): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Infrastructure\Adapter; | ||
|
||
use App\Application\Exception\BothDirectionsNotSupportedAtPointNumbers; | ||
use App\Application\PointNumberSideDetectorInterface; | ||
use App\Application\RoadGeocoderInterface; | ||
use App\Domain\Regulation\Enum\DirectionEnum; | ||
use App\Domain\Regulation\Enum\RoadSideEnum; | ||
use App\Domain\Regulation\Location\NumberedRoad; | ||
|
||
final class PointNumberSideDetector implements PointNumberSideDetectorInterface | ||
{ | ||
public function __construct( | ||
private readonly RoadGeocoderInterface $roadGeocoder, | ||
) { | ||
} | ||
|
||
public function detect( | ||
string $direction, | ||
string $administrator, | ||
string $roadNumber, | ||
string $fromPointNumber, | ||
int $fromAbscissa, | ||
string $toPointNumber, | ||
int $toAbscissa, | ||
): array { | ||
$sidesAtFromPoint = $this->roadGeocoder->getAvailableSidesAtPointNumber( | ||
$administrator, | ||
$roadNumber, | ||
$fromPointNumber, | ||
); | ||
|
||
$sidesAtToPoint = $this->roadGeocoder->getAvailableSidesAtPointNumber( | ||
$administrator, | ||
$roadNumber, | ||
$toPointNumber, | ||
); | ||
|
||
$isSingleWayAtFromPoint = \in_array(RoadSideEnum::U->value, $sidesAtFromPoint); | ||
$isSingleWayAtToPoint = \in_array(RoadSideEnum::U->value, $sidesAtToPoint); | ||
|
||
if ($isSingleWayAtFromPoint || $isSingleWayAtToPoint) { | ||
// L'un des deux PR au moins est sur une chaussée unique | ||
// On doit forcément utiliser des PR de type U. | ||
return [RoadSideEnum::U->value, RoadSideEnum::U->value]; | ||
} | ||
|
||
// Les deux PR se trouvent sur une section à chaussée séparée. | ||
// A priori, les deux côtés G ou D sont possibles au niveau de chaque PR. | ||
// On choisit le côté adéquat en fonction de la direction demandée et de l'ordre | ||
// des PR dans le sens des PR croissants. | ||
// Le "Double sens" n'est pas supporté pour l'instant, il faut saisir deux localisations, | ||
// une dans chaque sens. | ||
|
||
if ($direction === DirectionEnum::BOTH->value) { | ||
// TODO: handle in controller | ||
throw new BothDirectionsNotSupportedAtPointNumbers(); | ||
} | ||
|
||
if (NumberedRoad::comparePointNumber($fromPointNumber, $fromAbscissa, $toPointNumber, $toAbscissa) <= 0) { | ||
// Le PR A est situé avant le PR B, dans l'ordre des PR croissants. | ||
// On doit choisir le côté D si le sens A -> B est demandé, et le côté G sinon. | ||
$side = $direction === DirectionEnum::A_TO_B->value | ||
? RoadSideEnum::D->value | ||
: RoadSideEnum::G->value; | ||
|
||
return [$side, $side]; | ||
} | ||
|
||
// Le PR A est situé après le PR B, donc on choisit le côté G si A->B est demandé, et le côté D sinon. | ||
$side = $direction === DirectionEnum::A_TO_B->value | ||
? RoadSideEnum::G->value | ||
: RoadSideEnum::D->value; | ||
|
||
return [$side, $side]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters