@@ -18,12 +18,12 @@ final class SaveNumberedRoadCommand implements RoadCommandInterface
1818 public ?string $ roadType = null ; // Used by validation
1919 public ?string $ administrator = null ;
2020 public ?string $ roadNumber = null ;
21- public ?string $ fromPointNumber = null ;
2221 public ?string $ fromDepartmentCode = null ;
22+ public ?string $ fromPointNumber = null ;
2323 public ?int $ fromAbscissa = null ;
2424 public ?string $ fromSide = null ;
25- public ?string $ toPointNumber = null ;
2625 public ?string $ toDepartmentCode = null ;
26+ public ?string $ toPointNumber = null ;
2727 public ?int $ toAbscissa = null ;
2828 public ?string $ toSide = null ;
2929 public string $ direction = DirectionEnum::BOTH ->value ;
@@ -40,32 +40,32 @@ final class SaveNumberedRoadCommand implements RoadCommandInterface
4040 public function __construct (
4141 public ?NumberedRoad $ numberedRoad = null ,
4242 ) {
43- $ fromPointNumber = $ numberedRoad ?->getFromPointNumber();
4443 $ fromDepartmentCode = $ numberedRoad ?->getFromDepartmentCode();
45- $ toPointNumber = $ numberedRoad ?->getToPointNumber ();
44+ $ fromPointNumber = $ numberedRoad ?->getFromPointNumber ();
4645 $ toDepartmentCode = $ numberedRoad ?->getToDepartmentCode();
46+ $ toPointNumber = $ numberedRoad ?->getToPointNumber();
4747
4848 $ this ->administrator = $ numberedRoad ?->getAdministrator();
4949 $ this ->roadNumber = $ numberedRoad ?->getRoadNumber();
5050 $ this ->fromSide = $ numberedRoad ?->getFromSide();
51- $ this ->fromPointNumber = $ fromPointNumber ;
5251 $ this ->fromDepartmentCode = $ fromDepartmentCode ;
52+ $ this ->fromPointNumber = $ fromPointNumber ;
5353 $ this ->fromAbscissa = $ numberedRoad ?->getFromAbscissa();
54- $ this ->toPointNumber = $ toPointNumber ;
5554 $ this ->toDepartmentCode = $ toDepartmentCode ;
55+ $ this ->toPointNumber = $ toPointNumber ;
5656 $ this ->toAbscissa = $ numberedRoad ?->getToAbscissa();
5757 $ this ->toSide = $ numberedRoad ?->getToSide();
5858 $ this ->direction = $ numberedRoad ?->getDirection() ?? DirectionEnum::BOTH ->value ;
5959 $ this ->storageArea = $ numberedRoad ?->getLocation()?->getStorageArea();
6060 $ this ->roadType = $ numberedRoad ?->getLocation()?->getRoadType();
6161
62- $ this ->fromPointNumberValue = self ::encodePointNumberValue ($ fromPointNumber , $ fromDepartmentCode );
63- $ this ->fromPointNumberDisplayedValue = self ::encodePointNumberDisplayedValue ($ fromPointNumber , $ fromDepartmentCode );
64- $ this ->toPointNumberValue = self ::encodePointNumberValue ($ toPointNumber , $ toDepartmentCode );
65- $ this ->toPointNumberDisplayedValue = self ::encodePointNumberDisplayedValue ($ toPointNumber , $ toDepartmentCode );
62+ $ this ->fromPointNumberValue = self ::encodePointNumberValue ($ fromDepartmentCode , $ fromPointNumber );
63+ $ this ->fromPointNumberDisplayedValue = self ::encodePointNumberDisplayedValue ($ fromDepartmentCode , $ fromPointNumber );
64+ $ this ->toPointNumberValue = self ::encodePointNumberValue ($ toDepartmentCode , $ toPointNumber );
65+ $ this ->toPointNumberDisplayedValue = self ::encodePointNumberDisplayedValue ($ toDepartmentCode , $ toPointNumber );
6666 }
6767
68- public static function encodePointNumberValue (?string $ pointNumber , ?string $ departmentCode ): ?string
68+ public static function encodePointNumberValue (?string $ departmentCode , ?string $ pointNumber ): ?string
6969 {
7070 if (empty ($ pointNumber )) {
7171 return null ;
@@ -75,19 +75,23 @@ public static function encodePointNumberValue(?string $pointNumber, ?string $dep
7575 return $ pointNumber ;
7676 }
7777
78- return implode ('## ' , [$ pointNumber , $ departmentCode ]);
78+ return implode ('## ' , [$ departmentCode , $ pointNumber ]);
7979 }
8080
81- public static function decodePointNumberValue (string $ value ): array
81+ public static function decodePointNumberValue (? string $ value ): array
8282 {
83- // '122' -> ['122', null]
84- // '122#22' -> ['122', '22']
83+ if (empty ($ value )) {
84+ return [null , null ];
85+ }
86+
87+ // '122' -> [null, '122]
88+ // '122#22' -> ['22', '122']
8589 $ parts = explode ('## ' , $ value , 2 );
8690
87- return \count ($ parts ) === 2 ? $ parts : [$ value , null ];
91+ return \count ($ parts ) === 2 ? $ parts : [null , $ value ];
8892 }
8993
90- public static function encodePointNumberDisplayedValue (?string $ pointNumber , ?string $ departmentCode ): ?string
94+ public static function encodePointNumberDisplayedValue (?string $ departmentCode , ?string $ pointNumber ): ?string
9195 {
9296 if (empty ($ pointNumber )) {
9397 return null ;
@@ -118,7 +122,7 @@ public function clean(): void
118122 $ this ->storageArea = null ;
119123 }
120124
121- [$ this ->fromPointNumber , $ this ->fromDepartmentCode ] = self ::decodePointNumberValue ($ this ->fromPointNumberValue );
122- [$ this ->toPointNumber , $ this ->toDepartmentCode ] = self ::decodePointNumberValue ($ this ->toPointNumberValue );
125+ [$ this ->fromDepartmentCode , $ this ->fromPointNumber ] = self ::decodePointNumberValue ($ this ->fromPointNumberValue );
126+ [$ this ->toDepartmentCode , $ this ->toPointNumber ] = self ::decodePointNumberValue ($ this ->toPointNumberValue );
123127 }
124128}
0 commit comments