Skip to content

Commit 8a83002

Browse files
authored
Add UNKNOWN_TO_SDK value to enums (#1998)
fix 1921
1 parent 3996fe6 commit 8a83002

15 files changed

Lines changed: 42 additions & 4 deletions

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- Add `UNKNOWN_TO_SDK` value to enums that is used when the API returns an value that is not (or not yet) known by the AsyncAws
8+
59
### Dependency bumped
610

711
- Drop support for PHP versions lower than 8.2

src/Enum/DimensionUnit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ final class DimensionUnit
77
public const FEET = 'Feet';
88
public const METERS = 'Meters';
99

10+
/**
11+
* @psalm-assert-if-true self::* $value
12+
*/
1013
public static function exists(string $value): bool
1114
{
1215
return isset([

src/Enum/DistanceUnit.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ final class DistanceUnit
66
{
77
public const KILOMETERS = 'Kilometers';
88
public const MILES = 'Miles';
9+
public const UNKNOWN_TO_SDK = 'UNKNOWN_TO_SDK';
910

11+
/**
12+
* @psalm-assert-if-true self::* $value
13+
*/
1014
public static function exists(string $value): bool
1115
{
1216
return isset([

src/Enum/OptimizationMode.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ final class OptimizationMode
77
public const FASTEST_ROUTE = 'FastestRoute';
88
public const SHORTEST_ROUTE = 'ShortestRoute';
99

10+
/**
11+
* @psalm-assert-if-true self::* $value
12+
*/
1013
public static function exists(string $value): bool
1114
{
1215
return isset([

src/Enum/RouteMatrixErrorCode.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ final class RouteMatrixErrorCode
1010
public const POSITIONS_NOT_FOUND = 'PositionsNotFound';
1111
public const ROUTE_NOT_FOUND = 'RouteNotFound';
1212
public const ROUTE_TOO_LONG = 'RouteTooLong';
13+
public const UNKNOWN_TO_SDK = 'UNKNOWN_TO_SDK';
1314

15+
/**
16+
* @psalm-assert-if-true self::* $value
17+
*/
1418
public static function exists(string $value): bool
1519
{
1620
return isset([

src/Enum/TravelMode.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ final class TravelMode
1010
public const TRUCK = 'Truck';
1111
public const WALKING = 'Walking';
1212

13+
/**
14+
* @psalm-assert-if-true self::* $value
15+
*/
1316
public static function exists(string $value): bool
1417
{
1518
return isset([

src/Enum/ValidationExceptionReason.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ final class ValidationExceptionReason
1010
public const OTHER = 'Other';
1111
public const UNKNOWN_FIELD = 'UnknownField';
1212
public const UNKNOWN_OPERATION = 'UnknownOperation';
13+
public const UNKNOWN_TO_SDK = 'UNKNOWN_TO_SDK';
1314

15+
/**
16+
* @psalm-assert-if-true self::* $value
17+
*/
1418
public static function exists(string $value): bool
1519
{
1620
return isset([

src/Enum/VehicleWeightUnit.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ final class VehicleWeightUnit
77
public const KILOGRAMS = 'Kilograms';
88
public const POUNDS = 'Pounds';
99

10+
/**
11+
* @psalm-assert-if-true self::* $value
12+
*/
1013
public static function exists(string $value): bool
1114
{
1215
return isset([

src/Exception/ValidationException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ protected function populateResult(ResponseInterface $response): void
4646
{
4747
$data = $response->toArray(false);
4848

49-
$this->reason = (string) $data['reason'];
49+
$this->reason = !ValidationExceptionReason::exists((string) $data['reason']) ? ValidationExceptionReason::UNKNOWN_TO_SDK : (string) $data['reason'];
5050
$this->fieldList = $this->populateResultValidationExceptionFieldList($data['fieldList'] ?? []);
5151
}
5252

src/Input/CalculateRouteMatrixRequest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ private function requestBody(): array
424424

425425
if (null !== $v = $this->travelMode) {
426426
if (!TravelMode::exists($v)) {
427+
/** @psalm-suppress NoValue */
427428
throw new InvalidArgument(\sprintf('Invalid parameter "TravelMode" for "%s". The value "%s" is not a valid "TravelMode".', __CLASS__, $v));
428429
}
429430
$payload['TravelMode'] = $v;
@@ -436,6 +437,7 @@ private function requestBody(): array
436437
}
437438
if (null !== $v = $this->distanceUnit) {
438439
if (!DistanceUnit::exists($v)) {
440+
/** @psalm-suppress NoValue */
439441
throw new InvalidArgument(\sprintf('Invalid parameter "DistanceUnit" for "%s". The value "%s" is not a valid "DistanceUnit".', __CLASS__, $v));
440442
}
441443
$payload['DistanceUnit'] = $v;

0 commit comments

Comments
 (0)