diff --git a/src/CodeGenerator/src/Generator/InputGenerator.php b/src/CodeGenerator/src/Generator/InputGenerator.php index b9b6db316..038ebb607 100644 --- a/src/CodeGenerator/src/Generator/InputGenerator.php +++ b/src/CodeGenerator/src/Generator/InputGenerator.php @@ -429,7 +429,7 @@ private function inputClassRequestGetters(StructureShape $inputShape, ClassBuild if ($operation->hasBody()) { [$body['body'], $hasRequestBody, $overrideArgs] = $serializer->generateRequestBody($operation, $inputShape) + [null, null, []]; if ($hasRequestBody) { - [$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($inputShape) + [null, null, []]; + [$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($inputShape, true) + [null, null, []]; if ('' === trim($requestBody)) { $body['body'] = '$body = "";'; } else { diff --git a/src/CodeGenerator/src/Generator/ObjectGenerator.php b/src/CodeGenerator/src/Generator/ObjectGenerator.php index f930a7bf7..878d851c7 100644 --- a/src/CodeGenerator/src/Generator/ObjectGenerator.php +++ b/src/CodeGenerator/src/Generator/ObjectGenerator.php @@ -106,7 +106,7 @@ public function generate(StructureShape $shape, bool $forEndpoint = false): Clas $serializer = $this->serializer->get($shape->getService()); if ($this->isShapeUsedInput($shape)) { - [$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($shape) + [null, null, []]; + [$returnType, $requestBody, $args] = $serializer->generateRequestBuilder($shape, false) + [null, null, []]; $method = $classBuilder->addMethod('requestBody')->setReturnType($returnType)->setBody($requestBody)->setPublic()->setComment('@internal'); foreach ($args as $arg => $type) { $method->addParameter($arg)->setType($type); @@ -191,36 +191,60 @@ private function namedConstructor(StructureShape $shape, ClassBuilder $classBuil $constructor->addParameter('input')->setType('array'); + // To throw an exception in an expression, we need to use a method to support PHP 7.x + $needsThrowMethod = false; + $constructorBody = ''; foreach ($shape->getMembers() as $member) { $memberShape = $member->getShape(); if ($memberShape instanceof StructureShape) { $objectClass = $this->generate($memberShape); - $constructorBody .= strtr('$this->PROPERTY = isset($input["NAME"]) ? CLASS::create($input["NAME"]) : null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); + $memberCode = strtr('CLASS::create($input["NAME"])', ['NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); } elseif ($memberShape instanceof ListShape) { $listMemberShape = $memberShape->getMember()->getShape(); // Check if this is a list of objects if ($listMemberShape instanceof StructureShape) { $objectClass = $this->generate($listMemberShape); - $constructorBody .= strtr('$this->PROPERTY = isset($input["NAME"]) ? array_map([CLASS::class, "create"], $input["NAME"]) : null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); + $memberCode = strtr('array_map([CLASS::class, "create"], $input["NAME"])', ['NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); } else { - $constructorBody .= strtr('$this->PROPERTY = $input["NAME"] ?? null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName()]); + $memberCode = strtr('$input["NAME"]', ['NAME' => $member->getName()]); } } elseif ($memberShape instanceof MapShape) { $mapValueShape = $memberShape->getValue()->getShape(); if ($mapValueShape instanceof StructureShape) { $objectClass = $this->generate($mapValueShape); - $constructorBody .= strtr('$this->PROPERTY = isset($input["NAME"]) ? array_map([CLASS::class, "create"], $input["NAME"]) : null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); + $memberCode = strtr('array_map([CLASS::class, "create"], $input["NAME"])', ['NAME' => $member->getName(), 'CLASS' => $objectClass->getName()]); } else { - $constructorBody .= strtr('$this->PROPERTY = $input["NAME"] ?? null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName()]); + $memberCode = strtr('$input["NAME"]', ['NAME' => $member->getName()]); } } else { - $constructorBody .= strtr('$this->PROPERTY = $input["NAME"] ?? null;' . "\n", ['PROPERTY' => GeneratorHelper::normalizeName($member->getName()), 'NAME' => $member->getName()]); + $memberCode = strtr('$input["NAME"]', ['NAME' => $member->getName()]); + } + if ($member->isRequired()) { + $fallback = strtr('$this->throwException(new InvalidArgument(\'Missing required field "NAME".\'))', ['NAME' => $member->getName()]); + $classBuilder->addUse(InvalidArgument::class); + $needsThrowMethod = true; + } else { + $fallback = 'null'; } + $constructorBody .= strtr('$this->PROPERTY = isset($input["NAME"]) ? MEMBER_CODE : FALLBACK;' . "\n", [ + 'PROPERTY' => GeneratorHelper::normalizeName($member->getName()), + 'NAME' => $member->getName(), + 'MEMBER_CODE' => $memberCode, + 'FALLBACK' => $fallback, + ]); } $constructor->setBody($constructorBody); + + if ($needsThrowMethod) { + $throwMethod = $classBuilder->addMethod('throwException'); + $throwMethod->setPrivate(); + $throwMethod->addComment('@return never'); + $throwMethod->addParameter('exception')->setType(\Throwable::class); + $throwMethod->setBody('throw $exception;'); + } } /** @@ -249,12 +273,12 @@ private function addProperties(StructureShape $shape, ClassBuilder $classBuilder $enumClassName = $this->enumGenerator->generate($memberShape); $classBuilder->addUse($enumClassName->getFqdn()); } - $getterSetterNullable = true; + $getterSetterNullable = null; if ($memberShape instanceof StructureShape) { $this->generate($memberShape); } elseif ($memberShape instanceof MapShape) { - $nullable = $getterSetterNullable = false; + $getterSetterNullable = false; $mapKeyShape = $memberShape->getKey()->getShape(); if ('string' !== $mapKeyShape->getType()) { throw new \RuntimeException('Complex maps are not supported'); @@ -271,7 +295,7 @@ private function addProperties(StructureShape $shape, ClassBuilder $classBuilder $classBuilder->addUse($enumClassName->getFqdn()); } } elseif ($memberShape instanceof ListShape) { - $nullable = $getterSetterNullable = false; + $getterSetterNullable = false; $memberShape->getMember()->getShape(); if (($memberShape = $memberShape->getMember()->getShape()) instanceof StructureShape) { @@ -297,7 +321,10 @@ private function addProperties(StructureShape $shape, ClassBuilder $classBuilder $deprecation = strtr('@trigger_error(\sprintf(\'The property "NAME" of "%s" is deprecated by AWS.\', __CLASS__), E_USER_DEPRECATED);', ['NAME' => $member->getName()]); } - if ($getterSetterNullable) { + $nullable = $nullable ?? !$member->isRequired(); + $getterSetterNullable = $getterSetterNullable ?? $nullable; + + if ($getterSetterNullable || !$nullable) { $method->setBody($deprecation . strtr(' return $this->PROPERTY; ', [ @@ -311,11 +338,10 @@ private function addProperties(StructureShape $shape, ClassBuilder $classBuilder ])); } - $nullable = $nullable ?? !$member->isRequired(); if ($parameterType && $parameterType !== $returnType && (empty($memberClassNames) || $memberClassNames[0]->getName() !== $parameterType)) { - $method->addComment('@return ' . $parameterType . ($nullable ? '|null' : '')); + $method->addComment('@return ' . $parameterType . ($getterSetterNullable ? '|null' : '')); } - $method->setReturnNullable($nullable); + $method->setReturnNullable($getterSetterNullable); } foreach ($forEndpointProps as $key => $ok) { diff --git a/src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php b/src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php index 5445bc47b..0d27e68ea 100644 --- a/src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php +++ b/src/CodeGenerator/src/Generator/RequestSerializer/QuerySerializer.php @@ -69,9 +69,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape) ]), true]; } - public function generateRequestBuilder(StructureShape $shape): array + public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array { - $body = implode("\n", array_map(function (StructureMember $member) { + $body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) { if (null !== $member->getLocation()) { return ''; } @@ -84,10 +84,15 @@ public function generateRequestBuilder(StructureShape $shape): array MEMBER_CODE'; $inputElement = '$v'; } elseif ($member->isRequired()) { - $body = 'if (null === $v = $this->PROPERTY) { - throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + if ($needsChecks) { + $body = 'if (null === $v = $this->PROPERTY) { + throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + } + MEMBER_CODE'; + } else { + $body = '$v = $this->PROPERTY; + MEMBER_CODE'; } - MEMBER_CODE'; $inputElement = '$v'; } else { $body = 'if (null !== $v = $this->PROPERTY) { diff --git a/src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php b/src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php index db07cf388..1abe0a450 100644 --- a/src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php +++ b/src/CodeGenerator/src/Generator/RequestSerializer/RestJsonSerializer.php @@ -68,9 +68,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape) return ['$bodyPayload = $this->requestBody(); $body = empty($bodyPayload) ? "{}" : \json_encode($bodyPayload, ' . \JSON_THROW_ON_ERROR . ');', true]; } - public function generateRequestBuilder(StructureShape $shape): array + public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array { - $body = implode("\n", array_map(function (StructureMember $member) { + $body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) { if (null !== $member->getLocation()) { return ''; } @@ -83,10 +83,15 @@ public function generateRequestBuilder(StructureShape $shape): array MEMBER_CODE'; $inputElement = '$v'; } elseif ($member->isRequired()) { - $body = 'if (null === $v = $this->PROPERTY) { - throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + if ($needsChecks) { + $body = 'if (null === $v = $this->PROPERTY) { + throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + } + MEMBER_CODE'; + } else { + $body = '$v = $this->PROPERTY; + MEMBER_CODE'; } - MEMBER_CODE'; $inputElement = '$v'; } else { $body = 'if (null !== $v = $this->PROPERTY) { diff --git a/src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php b/src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php index 2d519279a..09b68851c 100644 --- a/src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php +++ b/src/CodeGenerator/src/Generator/RequestSerializer/RestXmlSerializer.php @@ -93,9 +93,9 @@ public function generateRequestBody(Operation $operation, StructureShape $shape) ', true, ['node' => \DOMNode::class]]; } - public function generateRequestBuilder(StructureShape $shape): array + public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array { - $body = implode("\n", array_map(function (StructureMember $member) { + $body = implode("\n", array_map(function (StructureMember $member) use ($needsChecks) { if (null !== $member->getLocation()) { return ''; } @@ -108,10 +108,15 @@ public function generateRequestBuilder(StructureShape $shape): array MEMBER_CODE'; $inputElement = '$v'; } elseif ($member->isRequired()) { - $body = 'if (null === $v = $this->PROPERTY) { - throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + if ($needsChecks) { + $body = 'if (null === $v = $this->PROPERTY) { + throw new InvalidArgument(sprintf(\'Missing parameter "NAME" for "%s". The value cannot be null.\', __CLASS__)); + } + MEMBER_CODE'; + } else { + $body = '$v = $this->PROPERTY; + MEMBER_CODE'; } - MEMBER_CODE'; $inputElement = '$v'; } else { $body = 'if (null !== $v = $this->PROPERTY) { diff --git a/src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php b/src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php index 2a4f9f635..8c6585abb 100644 --- a/src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php +++ b/src/CodeGenerator/src/Generator/RequestSerializer/Serializer.php @@ -29,7 +29,7 @@ public function generateRequestBody(Operation $operation, StructureShape $shape) * * @return array{0: string, 1: string, 2?: array} */ - public function generateRequestBuilder(StructureShape $shape): array; + public function generateRequestBuilder(StructureShape $shape, bool $needsChecks): array; public function getHeaders(Operation $operation): string; } diff --git a/src/Core/src/Sts/ValueObject/AssumedRoleUser.php b/src/Core/src/Sts/ValueObject/AssumedRoleUser.php index 40c0b922d..6b261f445 100644 --- a/src/Core/src/Sts/ValueObject/AssumedRoleUser.php +++ b/src/Core/src/Sts/ValueObject/AssumedRoleUser.php @@ -2,6 +2,8 @@ namespace AsyncAws\Core\Sts\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The identifiers for the temporary security credentials that the operation returns. */ @@ -29,8 +31,8 @@ final class AssumedRoleUser */ public function __construct(array $input) { - $this->assumedRoleId = $input['AssumedRoleId'] ?? null; - $this->arn = $input['Arn'] ?? null; + $this->assumedRoleId = $input['AssumedRoleId'] ?? $this->throwException(new InvalidArgument('Missing required field "AssumedRoleId".')); + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); } /** @@ -53,4 +55,12 @@ public function getAssumedRoleId(): string { return $this->assumedRoleId; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Core/src/Sts/ValueObject/Credentials.php b/src/Core/src/Sts/ValueObject/Credentials.php index eafc39ecb..74e316dc4 100644 --- a/src/Core/src/Sts/ValueObject/Credentials.php +++ b/src/Core/src/Sts/ValueObject/Credentials.php @@ -2,6 +2,8 @@ namespace AsyncAws\Core\Sts\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Amazon Web Services credentials for API authentication. */ @@ -37,10 +39,10 @@ final class Credentials */ public function __construct(array $input) { - $this->accessKeyId = $input['AccessKeyId'] ?? null; - $this->secretAccessKey = $input['SecretAccessKey'] ?? null; - $this->sessionToken = $input['SessionToken'] ?? null; - $this->expiration = $input['Expiration'] ?? null; + $this->accessKeyId = $input['AccessKeyId'] ?? $this->throwException(new InvalidArgument('Missing required field "AccessKeyId".')); + $this->secretAccessKey = $input['SecretAccessKey'] ?? $this->throwException(new InvalidArgument('Missing required field "SecretAccessKey".')); + $this->sessionToken = $input['SessionToken'] ?? $this->throwException(new InvalidArgument('Missing required field "SessionToken".')); + $this->expiration = $input['Expiration'] ?? $this->throwException(new InvalidArgument('Missing required field "Expiration".')); } /** @@ -75,4 +77,12 @@ public function getSessionToken(): string { return $this->sessionToken; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Core/src/Sts/ValueObject/Tag.php b/src/Core/src/Sts/ValueObject/Tag.php index 83d7649c4..d6791e459 100644 --- a/src/Core/src/Sts/ValueObject/Tag.php +++ b/src/Core/src/Sts/ValueObject/Tag.php @@ -41,8 +41,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -72,15 +72,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/AppSyncRuntime.php b/src/Service/AppSync/src/ValueObject/AppSyncRuntime.php index e4d458f9a..e6bda58bc 100644 --- a/src/Service/AppSync/src/ValueObject/AppSyncRuntime.php +++ b/src/Service/AppSync/src/ValueObject/AppSyncRuntime.php @@ -30,8 +30,8 @@ final class AppSyncRuntime */ public function __construct(array $input) { - $this->name = $input['name'] ?? null; - $this->runtimeVersion = $input['runtimeVersion'] ?? null; + $this->name = $input['name'] ?? $this->throwException(new InvalidArgument('Missing required field "name".')); + $this->runtimeVersion = $input['runtimeVersion'] ?? $this->throwException(new InvalidArgument('Missing required field "runtimeVersion".')); } /** @@ -64,18 +64,22 @@ public function getRuntimeVersion(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; if (!RuntimeName::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "name" for "%s". The value "%s" is not a valid "RuntimeName".', __CLASS__, $v)); } $payload['name'] = $v; - if (null === $v = $this->runtimeVersion) { - throw new InvalidArgument(sprintf('Missing parameter "runtimeVersion" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->runtimeVersion; $payload['runtimeVersion'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/AuthorizationConfig.php b/src/Service/AppSync/src/ValueObject/AuthorizationConfig.php index a81f67c53..037384773 100644 --- a/src/Service/AppSync/src/ValueObject/AuthorizationConfig.php +++ b/src/Service/AppSync/src/ValueObject/AuthorizationConfig.php @@ -30,7 +30,7 @@ final class AuthorizationConfig */ public function __construct(array $input) { - $this->authorizationType = $input['authorizationType'] ?? null; + $this->authorizationType = $input['authorizationType'] ?? $this->throwException(new InvalidArgument('Missing required field "authorizationType".')); $this->awsIamConfig = isset($input['awsIamConfig']) ? AwsIamConfig::create($input['awsIamConfig']) : null; } @@ -64,9 +64,7 @@ public function getAwsIamConfig(): ?AwsIamConfig public function requestBody(): array { $payload = []; - if (null === $v = $this->authorizationType) { - throw new InvalidArgument(sprintf('Missing parameter "authorizationType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->authorizationType; if (!AuthorizationType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "authorizationType" for "%s". The value "%s" is not a valid "AuthorizationType".', __CLASS__, $v)); } @@ -77,4 +75,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/CachingConfig.php b/src/Service/AppSync/src/ValueObject/CachingConfig.php index 63fc85c11..4c7f0078a 100644 --- a/src/Service/AppSync/src/ValueObject/CachingConfig.php +++ b/src/Service/AppSync/src/ValueObject/CachingConfig.php @@ -31,7 +31,7 @@ final class CachingConfig */ public function __construct(array $input) { - $this->ttl = $input['ttl'] ?? null; + $this->ttl = $input['ttl'] ?? $this->throwException(new InvalidArgument('Missing required field "ttl".')); $this->cachingKeys = $input['cachingKeys'] ?? null; } @@ -65,9 +65,7 @@ public function getTtl(): int public function requestBody(): array { $payload = []; - if (null === $v = $this->ttl) { - throw new InvalidArgument(sprintf('Missing parameter "ttl" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->ttl; $payload['ttl'] = $v; if (null !== $v = $this->cachingKeys) { $index = -1; @@ -80,4 +78,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/DynamodbDataSourceConfig.php b/src/Service/AppSync/src/ValueObject/DynamodbDataSourceConfig.php index 8e77782ee..ce718eebe 100644 --- a/src/Service/AppSync/src/ValueObject/DynamodbDataSourceConfig.php +++ b/src/Service/AppSync/src/ValueObject/DynamodbDataSourceConfig.php @@ -45,8 +45,8 @@ final class DynamodbDataSourceConfig */ public function __construct(array $input) { - $this->tableName = $input['tableName'] ?? null; - $this->awsRegion = $input['awsRegion'] ?? null; + $this->tableName = $input['tableName'] ?? $this->throwException(new InvalidArgument('Missing required field "tableName".')); + $this->awsRegion = $input['awsRegion'] ?? $this->throwException(new InvalidArgument('Missing required field "awsRegion".')); $this->useCallerCredentials = $input['useCallerCredentials'] ?? null; $this->deltaSyncConfig = isset($input['deltaSyncConfig']) ? DeltaSyncConfig::create($input['deltaSyncConfig']) : null; $this->versioned = $input['versioned'] ?? null; @@ -97,13 +97,9 @@ public function getVersioned(): ?bool public function requestBody(): array { $payload = []; - if (null === $v = $this->tableName) { - throw new InvalidArgument(sprintf('Missing parameter "tableName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tableName; $payload['tableName'] = $v; - if (null === $v = $this->awsRegion) { - throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->awsRegion; $payload['awsRegion'] = $v; if (null !== $v = $this->useCallerCredentials) { $payload['useCallerCredentials'] = (bool) $v; @@ -117,4 +113,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/ElasticsearchDataSourceConfig.php b/src/Service/AppSync/src/ValueObject/ElasticsearchDataSourceConfig.php index 5aeaf0b6f..33f72ddbd 100644 --- a/src/Service/AppSync/src/ValueObject/ElasticsearchDataSourceConfig.php +++ b/src/Service/AppSync/src/ValueObject/ElasticsearchDataSourceConfig.php @@ -30,8 +30,8 @@ final class ElasticsearchDataSourceConfig */ public function __construct(array $input) { - $this->endpoint = $input['endpoint'] ?? null; - $this->awsRegion = $input['awsRegion'] ?? null; + $this->endpoint = $input['endpoint'] ?? $this->throwException(new InvalidArgument('Missing required field "endpoint".')); + $this->awsRegion = $input['awsRegion'] ?? $this->throwException(new InvalidArgument('Missing required field "awsRegion".')); } /** @@ -61,15 +61,19 @@ public function getEndpoint(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->endpoint) { - throw new InvalidArgument(sprintf('Missing parameter "endpoint" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->endpoint; $payload['endpoint'] = $v; - if (null === $v = $this->awsRegion) { - throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->awsRegion; $payload['awsRegion'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/EventBridgeDataSourceConfig.php b/src/Service/AppSync/src/ValueObject/EventBridgeDataSourceConfig.php index 591f5623e..6ef78a7d9 100644 --- a/src/Service/AppSync/src/ValueObject/EventBridgeDataSourceConfig.php +++ b/src/Service/AppSync/src/ValueObject/EventBridgeDataSourceConfig.php @@ -23,7 +23,7 @@ final class EventBridgeDataSourceConfig */ public function __construct(array $input) { - $this->eventBusArn = $input['eventBusArn'] ?? null; + $this->eventBusArn = $input['eventBusArn'] ?? $this->throwException(new InvalidArgument('Missing required field "eventBusArn".')); } /** @@ -47,11 +47,17 @@ public function getEventBusArn(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->eventBusArn) { - throw new InvalidArgument(sprintf('Missing parameter "eventBusArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->eventBusArn; $payload['eventBusArn'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/LambdaDataSourceConfig.php b/src/Service/AppSync/src/ValueObject/LambdaDataSourceConfig.php index 1ad75301c..fc6151f7e 100644 --- a/src/Service/AppSync/src/ValueObject/LambdaDataSourceConfig.php +++ b/src/Service/AppSync/src/ValueObject/LambdaDataSourceConfig.php @@ -21,7 +21,7 @@ final class LambdaDataSourceConfig */ public function __construct(array $input) { - $this->lambdaFunctionArn = $input['lambdaFunctionArn'] ?? null; + $this->lambdaFunctionArn = $input['lambdaFunctionArn'] ?? $this->throwException(new InvalidArgument('Missing required field "lambdaFunctionArn".')); } /** @@ -45,11 +45,17 @@ public function getLambdaFunctionArn(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->lambdaFunctionArn) { - throw new InvalidArgument(sprintf('Missing parameter "lambdaFunctionArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->lambdaFunctionArn; $payload['lambdaFunctionArn'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/AppSync/src/ValueObject/OpenSearchServiceDataSourceConfig.php b/src/Service/AppSync/src/ValueObject/OpenSearchServiceDataSourceConfig.php index 0f273e914..2ae215318 100644 --- a/src/Service/AppSync/src/ValueObject/OpenSearchServiceDataSourceConfig.php +++ b/src/Service/AppSync/src/ValueObject/OpenSearchServiceDataSourceConfig.php @@ -27,8 +27,8 @@ final class OpenSearchServiceDataSourceConfig */ public function __construct(array $input) { - $this->endpoint = $input['endpoint'] ?? null; - $this->awsRegion = $input['awsRegion'] ?? null; + $this->endpoint = $input['endpoint'] ?? $this->throwException(new InvalidArgument('Missing required field "endpoint".')); + $this->awsRegion = $input['awsRegion'] ?? $this->throwException(new InvalidArgument('Missing required field "awsRegion".')); } /** @@ -58,15 +58,19 @@ public function getEndpoint(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->endpoint) { - throw new InvalidArgument(sprintf('Missing parameter "endpoint" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->endpoint; $payload['endpoint'] = $v; - if (null === $v = $this->awsRegion) { - throw new InvalidArgument(sprintf('Missing parameter "awsRegion" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->awsRegion; $payload['awsRegion'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/AclConfiguration.php b/src/Service/Athena/src/ValueObject/AclConfiguration.php index 5bc76cda0..5b3e385bb 100644 --- a/src/Service/Athena/src/ValueObject/AclConfiguration.php +++ b/src/Service/Athena/src/ValueObject/AclConfiguration.php @@ -31,7 +31,7 @@ final class AclConfiguration */ public function __construct(array $input) { - $this->s3AclOption = $input['S3AclOption'] ?? null; + $this->s3AclOption = $input['S3AclOption'] ?? $this->throwException(new InvalidArgument('Missing required field "S3AclOption".')); } /** @@ -58,9 +58,7 @@ public function getS3AclOption(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->s3AclOption) { - throw new InvalidArgument(sprintf('Missing parameter "S3AclOption" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->s3AclOption; if (!S3AclOption::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "S3AclOption" for "%s". The value "%s" is not a valid "S3AclOption".', __CLASS__, $v)); } @@ -68,4 +66,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/Column.php b/src/Service/Athena/src/ValueObject/Column.php index 1a01a4641..7914585b2 100644 --- a/src/Service/Athena/src/ValueObject/Column.php +++ b/src/Service/Athena/src/ValueObject/Column.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains metadata for a column in a table. */ @@ -31,7 +33,7 @@ final class Column */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->type = $input['Type'] ?? null; $this->comment = $input['Comment'] ?? null; } @@ -62,4 +64,12 @@ public function getType(): ?string { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/ColumnInfo.php b/src/Service/Athena/src/ValueObject/ColumnInfo.php index 2522c565c..b02e39914 100644 --- a/src/Service/Athena/src/ValueObject/ColumnInfo.php +++ b/src/Service/Athena/src/ValueObject/ColumnInfo.php @@ -3,6 +3,7 @@ namespace AsyncAws\Athena\ValueObject; use AsyncAws\Athena\Enum\ColumnNullable; +use AsyncAws\Core\Exception\InvalidArgument; /** * Information about the columns in a query execution result. @@ -79,9 +80,9 @@ public function __construct(array $input) $this->catalogName = $input['CatalogName'] ?? null; $this->schemaName = $input['SchemaName'] ?? null; $this->tableName = $input['TableName'] ?? null; - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->label = $input['Label'] ?? null; - $this->type = $input['Type'] ?? null; + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); $this->precision = $input['Precision'] ?? null; $this->scale = $input['Scale'] ?? null; $this->nullable = $input['Nullable'] ?? null; @@ -159,4 +160,12 @@ public function getType(): string { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/CustomerContentEncryptionConfiguration.php b/src/Service/Athena/src/ValueObject/CustomerContentEncryptionConfiguration.php index 37add0650..804fc9840 100644 --- a/src/Service/Athena/src/ValueObject/CustomerContentEncryptionConfiguration.php +++ b/src/Service/Athena/src/ValueObject/CustomerContentEncryptionConfiguration.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Specifies the KMS key that is used to encrypt the user's data stores in Athena. This setting does not apply to Athena * SQL workgroups. @@ -20,7 +22,7 @@ final class CustomerContentEncryptionConfiguration */ public function __construct(array $input) { - $this->kmsKey = $input['KmsKey'] ?? null; + $this->kmsKey = $input['KmsKey'] ?? $this->throwException(new InvalidArgument('Missing required field "KmsKey".')); } /** @@ -37,4 +39,12 @@ public function getKmsKey(): string { return $this->kmsKey; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/DataCatalog.php b/src/Service/Athena/src/ValueObject/DataCatalog.php index 9a7dd36b1..dfdce9319 100644 --- a/src/Service/Athena/src/ValueObject/DataCatalog.php +++ b/src/Service/Athena/src/ValueObject/DataCatalog.php @@ -3,6 +3,7 @@ namespace AsyncAws\Athena\ValueObject; use AsyncAws\Athena\Enum\DataCatalogType; +use AsyncAws\Core\Exception\InvalidArgument; /** * Contains information about a data catalog in an Amazon Web Services account. @@ -71,9 +72,9 @@ final class DataCatalog */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->description = $input['Description'] ?? null; - $this->type = $input['Type'] ?? null; + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); $this->parameters = $input['Parameters'] ?? null; } @@ -115,4 +116,12 @@ public function getType(): string { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/Database.php b/src/Service/Athena/src/ValueObject/Database.php index 083e9cad0..b6835a527 100644 --- a/src/Service/Athena/src/ValueObject/Database.php +++ b/src/Service/Athena/src/ValueObject/Database.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains metadata information for a database in a data catalog. */ @@ -31,7 +33,7 @@ final class Database */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->description = $input['Description'] ?? null; $this->parameters = $input['Parameters'] ?? null; } @@ -65,4 +67,12 @@ public function getParameters(): array { return $this->parameters ?? []; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/EncryptionConfiguration.php b/src/Service/Athena/src/ValueObject/EncryptionConfiguration.php index b8df45bf8..da56cd0d3 100644 --- a/src/Service/Athena/src/ValueObject/EncryptionConfiguration.php +++ b/src/Service/Athena/src/ValueObject/EncryptionConfiguration.php @@ -33,7 +33,7 @@ final class EncryptionConfiguration */ public function __construct(array $input) { - $this->encryptionOption = $input['EncryptionOption'] ?? null; + $this->encryptionOption = $input['EncryptionOption'] ?? $this->throwException(new InvalidArgument('Missing required field "EncryptionOption".')); $this->kmsKey = $input['KmsKey'] ?? null; } @@ -67,9 +67,7 @@ public function getKmsKey(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->encryptionOption) { - throw new InvalidArgument(sprintf('Missing parameter "EncryptionOption" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->encryptionOption; if (!EncryptionOption::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "EncryptionOption" for "%s". The value "%s" is not a valid "EncryptionOption".', __CLASS__, $v)); } @@ -80,4 +78,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/EngineConfiguration.php b/src/Service/Athena/src/ValueObject/EngineConfiguration.php index 3f4c88ec4..8debe4182 100644 --- a/src/Service/Athena/src/ValueObject/EngineConfiguration.php +++ b/src/Service/Athena/src/ValueObject/EngineConfiguration.php @@ -52,7 +52,7 @@ final class EngineConfiguration public function __construct(array $input) { $this->coordinatorDpuSize = $input['CoordinatorDpuSize'] ?? null; - $this->maxConcurrentDpus = $input['MaxConcurrentDpus'] ?? null; + $this->maxConcurrentDpus = $input['MaxConcurrentDpus'] ?? $this->throwException(new InvalidArgument('Missing required field "MaxConcurrentDpus".')); $this->defaultExecutorDpuSize = $input['DefaultExecutorDpuSize'] ?? null; $this->additionalConfigs = $input['AdditionalConfigs'] ?? null; $this->sparkProperties = $input['SparkProperties'] ?? null; @@ -112,9 +112,7 @@ public function requestBody(): array if (null !== $v = $this->coordinatorDpuSize) { $payload['CoordinatorDpuSize'] = $v; } - if (null === $v = $this->maxConcurrentDpus) { - throw new InvalidArgument(sprintf('Missing parameter "MaxConcurrentDpus" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->maxConcurrentDpus; $payload['MaxConcurrentDpus'] = $v; if (null !== $v = $this->defaultExecutorDpuSize) { $payload['DefaultExecutorDpuSize'] = $v; @@ -142,4 +140,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/NamedQuery.php b/src/Service/Athena/src/ValueObject/NamedQuery.php index 7804323a1..ab14dabc7 100644 --- a/src/Service/Athena/src/ValueObject/NamedQuery.php +++ b/src/Service/Athena/src/ValueObject/NamedQuery.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * A query, where `QueryString` contains the SQL statements that make up the query. */ @@ -49,10 +51,10 @@ final class NamedQuery */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->description = $input['Description'] ?? null; - $this->database = $input['Database'] ?? null; - $this->queryString = $input['QueryString'] ?? null; + $this->database = $input['Database'] ?? $this->throwException(new InvalidArgument('Missing required field "Database".')); + $this->queryString = $input['QueryString'] ?? $this->throwException(new InvalidArgument('Missing required field "QueryString".')); $this->namedQueryId = $input['NamedQueryId'] ?? null; $this->workGroup = $input['WorkGroup'] ?? null; } @@ -101,4 +103,12 @@ public function getWorkGroup(): ?string { return $this->workGroup; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/ResultReuseByAgeConfiguration.php b/src/Service/Athena/src/ValueObject/ResultReuseByAgeConfiguration.php index 9085bfc9b..b966260d6 100644 --- a/src/Service/Athena/src/ValueObject/ResultReuseByAgeConfiguration.php +++ b/src/Service/Athena/src/ValueObject/ResultReuseByAgeConfiguration.php @@ -28,7 +28,7 @@ final class ResultReuseByAgeConfiguration */ public function __construct(array $input) { - $this->enabled = $input['Enabled'] ?? null; + $this->enabled = $input['Enabled'] ?? $this->throwException(new InvalidArgument('Missing required field "Enabled".')); $this->maxAgeInMinutes = $input['MaxAgeInMinutes'] ?? null; } @@ -59,9 +59,7 @@ public function getMaxAgeInMinutes(): ?int public function requestBody(): array { $payload = []; - if (null === $v = $this->enabled) { - throw new InvalidArgument(sprintf('Missing parameter "Enabled" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->enabled; $payload['Enabled'] = (bool) $v; if (null !== $v = $this->maxAgeInMinutes) { $payload['MaxAgeInMinutes'] = $v; @@ -69,4 +67,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/ResultReuseInformation.php b/src/Service/Athena/src/ValueObject/ResultReuseInformation.php index 3057365fb..989272bd3 100644 --- a/src/Service/Athena/src/ValueObject/ResultReuseInformation.php +++ b/src/Service/Athena/src/ValueObject/ResultReuseInformation.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains information about whether the result of a previous query was reused. */ @@ -19,7 +21,7 @@ final class ResultReuseInformation */ public function __construct(array $input) { - $this->reusedPreviousResult = $input['ReusedPreviousResult'] ?? null; + $this->reusedPreviousResult = $input['ReusedPreviousResult'] ?? $this->throwException(new InvalidArgument('Missing required field "ReusedPreviousResult".')); } /** @@ -36,4 +38,12 @@ public function getReusedPreviousResult(): bool { return $this->reusedPreviousResult; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/TableMetadata.php b/src/Service/Athena/src/ValueObject/TableMetadata.php index f1e4d6f4e..bc2c9194a 100644 --- a/src/Service/Athena/src/ValueObject/TableMetadata.php +++ b/src/Service/Athena/src/ValueObject/TableMetadata.php @@ -2,6 +2,8 @@ namespace AsyncAws\Athena\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains metadata for a table. */ @@ -55,7 +57,7 @@ final class TableMetadata */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->createTime = $input['CreateTime'] ?? null; $this->lastAccessTime = $input['LastAccessTime'] ?? null; $this->tableType = $input['TableType'] ?? null; @@ -123,4 +125,12 @@ public function getTableType(): ?string { return $this->tableType; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Athena/src/ValueObject/WorkGroup.php b/src/Service/Athena/src/ValueObject/WorkGroup.php index c95831967..e93377a30 100644 --- a/src/Service/Athena/src/ValueObject/WorkGroup.php +++ b/src/Service/Athena/src/ValueObject/WorkGroup.php @@ -3,6 +3,7 @@ namespace AsyncAws\Athena\ValueObject; use AsyncAws\Athena\Enum\WorkGroupState; +use AsyncAws\Core\Exception\InvalidArgument; /** * A workgroup, which contains a name, description, creation time, state, and other configuration, listed under @@ -56,7 +57,7 @@ final class WorkGroup */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->state = $input['State'] ?? null; $this->configuration = isset($input['Configuration']) ? WorkGroupConfiguration::create($input['Configuration']) : null; $this->description = $input['Description'] ?? null; @@ -104,4 +105,12 @@ public function getState(): ?string { return $this->state; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFormation/src/ValueObject/RollbackTrigger.php b/src/Service/CloudFormation/src/ValueObject/RollbackTrigger.php index cbc766519..23b55e2ec 100644 --- a/src/Service/CloudFormation/src/ValueObject/RollbackTrigger.php +++ b/src/Service/CloudFormation/src/ValueObject/RollbackTrigger.php @@ -2,6 +2,8 @@ namespace AsyncAws\CloudFormation\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * A rollback trigger CloudFormation monitors during creation and updating of stacks. If any of the alarms you specify * goes to ALARM state during the stack operation or within the specified monitoring period afterwards, CloudFormation @@ -33,8 +35,8 @@ final class RollbackTrigger */ public function __construct(array $input) { - $this->arn = $input['Arn'] ?? null; - $this->type = $input['Type'] ?? null; + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); } /** @@ -57,4 +59,12 @@ public function getType(): string { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFormation/src/ValueObject/Stack.php b/src/Service/CloudFormation/src/ValueObject/Stack.php index a6508d116..7874e056c 100644 --- a/src/Service/CloudFormation/src/ValueObject/Stack.php +++ b/src/Service/CloudFormation/src/ValueObject/Stack.php @@ -4,6 +4,7 @@ use AsyncAws\CloudFormation\Enum\Capability; use AsyncAws\CloudFormation\Enum\StackStatus; +use AsyncAws\Core\Exception\InvalidArgument; /** * The Stack data type. @@ -174,15 +175,15 @@ final class Stack public function __construct(array $input) { $this->stackId = $input['StackId'] ?? null; - $this->stackName = $input['StackName'] ?? null; + $this->stackName = $input['StackName'] ?? $this->throwException(new InvalidArgument('Missing required field "StackName".')); $this->changeSetId = $input['ChangeSetId'] ?? null; $this->description = $input['Description'] ?? null; $this->parameters = isset($input['Parameters']) ? array_map([Parameter::class, 'create'], $input['Parameters']) : null; - $this->creationTime = $input['CreationTime'] ?? null; + $this->creationTime = $input['CreationTime'] ?? $this->throwException(new InvalidArgument('Missing required field "CreationTime".')); $this->deletionTime = $input['DeletionTime'] ?? null; $this->lastUpdatedTime = $input['LastUpdatedTime'] ?? null; $this->rollbackConfiguration = isset($input['RollbackConfiguration']) ? RollbackConfiguration::create($input['RollbackConfiguration']) : null; - $this->stackStatus = $input['StackStatus'] ?? null; + $this->stackStatus = $input['StackStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "StackStatus".')); $this->stackStatusReason = $input['StackStatusReason'] ?? null; $this->disableRollback = $input['DisableRollback'] ?? null; $this->notificationArns = $input['NotificationARNs'] ?? null; @@ -355,4 +356,12 @@ public function getTimeoutInMinutes(): ?int { return $this->timeoutInMinutes; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFormation/src/ValueObject/StackDriftInformation.php b/src/Service/CloudFormation/src/ValueObject/StackDriftInformation.php index 9ad4f4282..fda7a796d 100644 --- a/src/Service/CloudFormation/src/ValueObject/StackDriftInformation.php +++ b/src/Service/CloudFormation/src/ValueObject/StackDriftInformation.php @@ -3,6 +3,7 @@ namespace AsyncAws\CloudFormation\ValueObject; use AsyncAws\CloudFormation\Enum\StackDriftStatus; +use AsyncAws\Core\Exception\InvalidArgument; /** * Contains information about whether the stack's actual configuration differs, or has *drifted*, from its expected @@ -36,7 +37,7 @@ final class StackDriftInformation */ public function __construct(array $input) { - $this->stackDriftStatus = $input['StackDriftStatus'] ?? null; + $this->stackDriftStatus = $input['StackDriftStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "StackDriftStatus".')); $this->lastCheckTimestamp = $input['LastCheckTimestamp'] ?? null; } @@ -63,4 +64,12 @@ public function getStackDriftStatus(): string { return $this->stackDriftStatus; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFormation/src/ValueObject/StackEvent.php b/src/Service/CloudFormation/src/ValueObject/StackEvent.php index 048ba966a..3aba0d011 100644 --- a/src/Service/CloudFormation/src/ValueObject/StackEvent.php +++ b/src/Service/CloudFormation/src/ValueObject/StackEvent.php @@ -6,6 +6,7 @@ use AsyncAws\CloudFormation\Enum\HookInvocationPoint; use AsyncAws\CloudFormation\Enum\HookStatus; use AsyncAws\CloudFormation\Enum\ResourceStatus; +use AsyncAws\Core\Exception\InvalidArgument; /** * The StackEvent data type. @@ -129,13 +130,13 @@ final class StackEvent */ public function __construct(array $input) { - $this->stackId = $input['StackId'] ?? null; - $this->eventId = $input['EventId'] ?? null; - $this->stackName = $input['StackName'] ?? null; + $this->stackId = $input['StackId'] ?? $this->throwException(new InvalidArgument('Missing required field "StackId".')); + $this->eventId = $input['EventId'] ?? $this->throwException(new InvalidArgument('Missing required field "EventId".')); + $this->stackName = $input['StackName'] ?? $this->throwException(new InvalidArgument('Missing required field "StackName".')); $this->logicalResourceId = $input['LogicalResourceId'] ?? null; $this->physicalResourceId = $input['PhysicalResourceId'] ?? null; $this->resourceType = $input['ResourceType'] ?? null; - $this->timestamp = $input['Timestamp'] ?? null; + $this->timestamp = $input['Timestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "Timestamp".')); $this->resourceStatus = $input['ResourceStatus'] ?? null; $this->resourceStatusReason = $input['ResourceStatusReason'] ?? null; $this->resourceProperties = $input['ResourceProperties'] ?? null; @@ -263,4 +264,12 @@ public function getTimestamp(): \DateTimeImmutable { return $this->timestamp; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFormation/src/ValueObject/Tag.php b/src/Service/CloudFormation/src/ValueObject/Tag.php index 7cb49022e..73e07037c 100644 --- a/src/Service/CloudFormation/src/ValueObject/Tag.php +++ b/src/Service/CloudFormation/src/ValueObject/Tag.php @@ -2,6 +2,8 @@ namespace AsyncAws\CloudFormation\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The Tag type enables you to specify a key-value pair that can be used to store information about an CloudFormation * stack. @@ -27,8 +29,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -51,4 +53,12 @@ public function getValue(): string { return $this->value; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFront/src/ValueObject/Invalidation.php b/src/Service/CloudFront/src/ValueObject/Invalidation.php index 97aa77bd6..c5a83ed8c 100644 --- a/src/Service/CloudFront/src/ValueObject/Invalidation.php +++ b/src/Service/CloudFront/src/ValueObject/Invalidation.php @@ -2,6 +2,8 @@ namespace AsyncAws\CloudFront\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * An invalidation. */ @@ -37,10 +39,10 @@ final class Invalidation */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->status = $input['Status'] ?? null; - $this->createTime = $input['CreateTime'] ?? null; - $this->invalidationBatch = isset($input['InvalidationBatch']) ? InvalidationBatch::create($input['InvalidationBatch']) : null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".')); + $this->createTime = $input['CreateTime'] ?? $this->throwException(new InvalidArgument('Missing required field "CreateTime".')); + $this->invalidationBatch = isset($input['InvalidationBatch']) ? InvalidationBatch::create($input['InvalidationBatch']) : $this->throwException(new InvalidArgument('Missing required field "InvalidationBatch".')); } /** @@ -75,4 +77,12 @@ public function getStatus(): string { return $this->status; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFront/src/ValueObject/InvalidationBatch.php b/src/Service/CloudFront/src/ValueObject/InvalidationBatch.php index c14f1fbf2..f32a7abf3 100644 --- a/src/Service/CloudFront/src/ValueObject/InvalidationBatch.php +++ b/src/Service/CloudFront/src/ValueObject/InvalidationBatch.php @@ -40,8 +40,8 @@ final class InvalidationBatch */ public function __construct(array $input) { - $this->paths = isset($input['Paths']) ? Paths::create($input['Paths']) : null; - $this->callerReference = $input['CallerReference'] ?? null; + $this->paths = isset($input['Paths']) ? Paths::create($input['Paths']) : $this->throwException(new InvalidArgument('Missing required field "Paths".')); + $this->callerReference = $input['CallerReference'] ?? $this->throwException(new InvalidArgument('Missing required field "CallerReference".')); } /** @@ -70,17 +70,21 @@ public function getPaths(): Paths */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->paths) { - throw new InvalidArgument(sprintf('Missing parameter "Paths" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->paths; $node->appendChild($child = $document->createElement('Paths')); $v->requestBody($child, $document); - if (null === $v = $this->callerReference) { - throw new InvalidArgument(sprintf('Missing parameter "CallerReference" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->callerReference; $node->appendChild($document->createElement('CallerReference', $v)); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudFront/src/ValueObject/Paths.php b/src/Service/CloudFront/src/ValueObject/Paths.php index 8a757fe6d..a506b0325 100644 --- a/src/Service/CloudFront/src/ValueObject/Paths.php +++ b/src/Service/CloudFront/src/ValueObject/Paths.php @@ -30,7 +30,7 @@ final class Paths */ public function __construct(array $input) { - $this->quantity = $input['Quantity'] ?? null; + $this->quantity = $input['Quantity'] ?? $this->throwException(new InvalidArgument('Missing required field "Quantity".')); $this->items = $input['Items'] ?? null; } @@ -63,9 +63,7 @@ public function getQuantity(): int */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->quantity) { - throw new InvalidArgument(sprintf('Missing parameter "Quantity" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->quantity; $node->appendChild($document->createElement('Quantity', (string) $v)); if (null !== $v = $this->items) { $node->appendChild($nodeList = $document->createElement('Items')); @@ -74,4 +72,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void } } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/Dimension.php b/src/Service/CloudWatch/src/ValueObject/Dimension.php index 51545e803..08c96a026 100644 --- a/src/Service/CloudWatch/src/ValueObject/Dimension.php +++ b/src/Service/CloudWatch/src/ValueObject/Dimension.php @@ -35,8 +35,8 @@ final class Dimension */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->value = $input['Value'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -66,15 +66,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/DimensionFilter.php b/src/Service/CloudWatch/src/ValueObject/DimensionFilter.php index cc2c30f0b..5c7942921 100644 --- a/src/Service/CloudWatch/src/ValueObject/DimensionFilter.php +++ b/src/Service/CloudWatch/src/ValueObject/DimensionFilter.php @@ -27,7 +27,7 @@ final class DimensionFilter */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->value = $input['Value'] ?? null; } @@ -58,9 +58,7 @@ public function getValue(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; if (null !== $v = $this->value) { $payload['Value'] = $v; @@ -68,4 +66,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/MetricDataQuery.php b/src/Service/CloudWatch/src/ValueObject/MetricDataQuery.php index 106acafab..1705bc1de 100644 --- a/src/Service/CloudWatch/src/ValueObject/MetricDataQuery.php +++ b/src/Service/CloudWatch/src/ValueObject/MetricDataQuery.php @@ -117,7 +117,7 @@ final class MetricDataQuery */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); $this->metricStat = isset($input['MetricStat']) ? MetricStat::create($input['MetricStat']) : null; $this->expression = $input['Expression'] ?? null; $this->label = $input['Label'] ?? null; @@ -183,9 +183,7 @@ public function getReturnData(): ?bool public function requestBody(): array { $payload = []; - if (null === $v = $this->id) { - throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->id; $payload['Id'] = $v; if (null !== $v = $this->metricStat) { foreach ($v->requestBody() as $bodyKey => $bodyValue) { @@ -210,4 +208,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/MetricDatum.php b/src/Service/CloudWatch/src/ValueObject/MetricDatum.php index 5f9d93883..0d5076868 100644 --- a/src/Service/CloudWatch/src/ValueObject/MetricDatum.php +++ b/src/Service/CloudWatch/src/ValueObject/MetricDatum.php @@ -96,7 +96,7 @@ final class MetricDatum */ public function __construct(array $input) { - $this->metricName = $input['MetricName'] ?? null; + $this->metricName = $input['MetricName'] ?? $this->throwException(new InvalidArgument('Missing required field "MetricName".')); $this->dimensions = isset($input['Dimensions']) ? array_map([Dimension::class, 'create'], $input['Dimensions']) : null; $this->timestamp = $input['Timestamp'] ?? null; $this->value = $input['Value'] ?? null; @@ -188,9 +188,7 @@ public function getValues(): array public function requestBody(): array { $payload = []; - if (null === $v = $this->metricName) { - throw new InvalidArgument(sprintf('Missing parameter "MetricName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->metricName; $payload['MetricName'] = $v; if (null !== $v = $this->dimensions) { $index = 0; @@ -238,4 +236,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/MetricStat.php b/src/Service/CloudWatch/src/ValueObject/MetricStat.php index 88558532f..412211358 100644 --- a/src/Service/CloudWatch/src/ValueObject/MetricStat.php +++ b/src/Service/CloudWatch/src/ValueObject/MetricStat.php @@ -55,9 +55,9 @@ final class MetricStat */ public function __construct(array $input) { - $this->metric = isset($input['Metric']) ? Metric::create($input['Metric']) : null; - $this->period = $input['Period'] ?? null; - $this->stat = $input['Stat'] ?? null; + $this->metric = isset($input['Metric']) ? Metric::create($input['Metric']) : $this->throwException(new InvalidArgument('Missing required field "Metric".')); + $this->period = $input['Period'] ?? $this->throwException(new InvalidArgument('Missing required field "Period".')); + $this->stat = $input['Stat'] ?? $this->throwException(new InvalidArgument('Missing required field "Stat".')); $this->unit = $input['Unit'] ?? null; } @@ -103,20 +103,14 @@ public function getUnit(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->metric) { - throw new InvalidArgument(sprintf('Missing parameter "Metric" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->metric; foreach ($v->requestBody() as $bodyKey => $bodyValue) { $payload["Metric.$bodyKey"] = $bodyValue; } - if (null === $v = $this->period) { - throw new InvalidArgument(sprintf('Missing parameter "Period" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->period; $payload['Period'] = $v; - if (null === $v = $this->stat) { - throw new InvalidArgument(sprintf('Missing parameter "Stat" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->stat; $payload['Stat'] = $v; if (null !== $v = $this->unit) { if (!StandardUnit::exists($v)) { @@ -127,4 +121,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatch/src/ValueObject/StatisticSet.php b/src/Service/CloudWatch/src/ValueObject/StatisticSet.php index 2f4f812b8..4d3bcc38a 100644 --- a/src/Service/CloudWatch/src/ValueObject/StatisticSet.php +++ b/src/Service/CloudWatch/src/ValueObject/StatisticSet.php @@ -39,10 +39,10 @@ final class StatisticSet */ public function __construct(array $input) { - $this->sampleCount = $input['SampleCount'] ?? null; - $this->sum = $input['Sum'] ?? null; - $this->minimum = $input['Minimum'] ?? null; - $this->maximum = $input['Maximum'] ?? null; + $this->sampleCount = $input['SampleCount'] ?? $this->throwException(new InvalidArgument('Missing required field "SampleCount".')); + $this->sum = $input['Sum'] ?? $this->throwException(new InvalidArgument('Missing required field "Sum".')); + $this->minimum = $input['Minimum'] ?? $this->throwException(new InvalidArgument('Missing required field "Minimum".')); + $this->maximum = $input['Maximum'] ?? $this->throwException(new InvalidArgument('Missing required field "Maximum".')); } /** @@ -84,23 +84,23 @@ public function getSum(): float public function requestBody(): array { $payload = []; - if (null === $v = $this->sampleCount) { - throw new InvalidArgument(sprintf('Missing parameter "SampleCount" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->sampleCount; $payload['SampleCount'] = $v; - if (null === $v = $this->sum) { - throw new InvalidArgument(sprintf('Missing parameter "Sum" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->sum; $payload['Sum'] = $v; - if (null === $v = $this->minimum) { - throw new InvalidArgument(sprintf('Missing parameter "Minimum" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->minimum; $payload['Minimum'] = $v; - if (null === $v = $this->maximum) { - throw new InvalidArgument(sprintf('Missing parameter "Maximum" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->maximum; $payload['Maximum'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CloudWatchLogs/src/ValueObject/InputLogEvent.php b/src/Service/CloudWatchLogs/src/ValueObject/InputLogEvent.php index 08541368e..b2733c501 100644 --- a/src/Service/CloudWatchLogs/src/ValueObject/InputLogEvent.php +++ b/src/Service/CloudWatchLogs/src/ValueObject/InputLogEvent.php @@ -28,8 +28,8 @@ final class InputLogEvent */ public function __construct(array $input) { - $this->timestamp = $input['timestamp'] ?? null; - $this->message = $input['message'] ?? null; + $this->timestamp = $input['timestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "timestamp".')); + $this->message = $input['message'] ?? $this->throwException(new InvalidArgument('Missing required field "message".')); } /** @@ -59,15 +59,19 @@ public function getTimestamp(): int public function requestBody(): array { $payload = []; - if (null === $v = $this->timestamp) { - throw new InvalidArgument(sprintf('Missing parameter "timestamp" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->timestamp; $payload['timestamp'] = $v; - if (null === $v = $this->message) { - throw new InvalidArgument(sprintf('Missing parameter "message" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->message; $payload['message'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/CloudWatchLogsConfig.php b/src/Service/CodeBuild/src/ValueObject/CloudWatchLogsConfig.php index feacbdebe..5774c94a6 100644 --- a/src/Service/CodeBuild/src/ValueObject/CloudWatchLogsConfig.php +++ b/src/Service/CodeBuild/src/ValueObject/CloudWatchLogsConfig.php @@ -43,7 +43,7 @@ final class CloudWatchLogsConfig */ public function __construct(array $input) { - $this->status = $input['status'] ?? null; + $this->status = $input['status'] ?? $this->throwException(new InvalidArgument('Missing required field "status".')); $this->groupName = $input['groupName'] ?? null; $this->streamName = $input['streamName'] ?? null; } @@ -84,9 +84,7 @@ public function getStreamName(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->status) { - throw new InvalidArgument(sprintf('Missing parameter "status" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->status; if (!LogsConfigStatusType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "status" for "%s". The value "%s" is not a valid "LogsConfigStatusType".', __CLASS__, $v)); } @@ -100,4 +98,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/EnvironmentVariable.php b/src/Service/CodeBuild/src/ValueObject/EnvironmentVariable.php index 54c1828c4..2be342f62 100644 --- a/src/Service/CodeBuild/src/ValueObject/EnvironmentVariable.php +++ b/src/Service/CodeBuild/src/ValueObject/EnvironmentVariable.php @@ -48,8 +48,8 @@ final class EnvironmentVariable */ public function __construct(array $input) { - $this->name = $input['name'] ?? null; - $this->value = $input['value'] ?? null; + $this->name = $input['name'] ?? $this->throwException(new InvalidArgument('Missing required field "name".')); + $this->value = $input['value'] ?? $this->throwException(new InvalidArgument('Missing required field "value".')); $this->type = $input['type'] ?? null; } @@ -89,13 +89,9 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['value'] = $v; if (null !== $v = $this->type) { if (!EnvironmentVariableType::exists($v)) { @@ -106,4 +102,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/GitSubmodulesConfig.php b/src/Service/CodeBuild/src/ValueObject/GitSubmodulesConfig.php index 9d382104b..f43f49fc4 100644 --- a/src/Service/CodeBuild/src/ValueObject/GitSubmodulesConfig.php +++ b/src/Service/CodeBuild/src/ValueObject/GitSubmodulesConfig.php @@ -21,7 +21,7 @@ final class GitSubmodulesConfig */ public function __construct(array $input) { - $this->fetchSubmodules = $input['fetchSubmodules'] ?? null; + $this->fetchSubmodules = $input['fetchSubmodules'] ?? $this->throwException(new InvalidArgument('Missing required field "fetchSubmodules".')); } /** @@ -45,11 +45,17 @@ public function getFetchSubmodules(): bool public function requestBody(): array { $payload = []; - if (null === $v = $this->fetchSubmodules) { - throw new InvalidArgument(sprintf('Missing parameter "fetchSubmodules" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->fetchSubmodules; $payload['fetchSubmodules'] = (bool) $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/ProjectArtifacts.php b/src/Service/CodeBuild/src/ValueObject/ProjectArtifacts.php index 32258ffca..6cb6880e0 100644 --- a/src/Service/CodeBuild/src/ValueObject/ProjectArtifacts.php +++ b/src/Service/CodeBuild/src/ValueObject/ProjectArtifacts.php @@ -136,7 +136,7 @@ final class ProjectArtifacts */ public function __construct(array $input) { - $this->type = $input['type'] ?? null; + $this->type = $input['type'] ?? $this->throwException(new InvalidArgument('Missing required field "type".')); $this->location = $input['location'] ?? null; $this->path = $input['path'] ?? null; $this->namespaceType = $input['namespaceType'] ?? null; @@ -235,9 +235,7 @@ public function getType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!ArtifactsType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "type" for "%s". The value "%s" is not a valid "ArtifactsType".', __CLASS__, $v)); } @@ -281,4 +279,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/ProjectCache.php b/src/Service/CodeBuild/src/ValueObject/ProjectCache.php index 910e35670..b88de7aa7 100644 --- a/src/Service/CodeBuild/src/ValueObject/ProjectCache.php +++ b/src/Service/CodeBuild/src/ValueObject/ProjectCache.php @@ -71,7 +71,7 @@ final class ProjectCache */ public function __construct(array $input) { - $this->type = $input['type'] ?? null; + $this->type = $input['type'] ?? $this->throwException(new InvalidArgument('Missing required field "type".')); $this->location = $input['location'] ?? null; $this->modes = $input['modes'] ?? null; } @@ -115,9 +115,7 @@ public function getType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!CacheType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "type" for "%s". The value "%s" is not a valid "CacheType".', __CLASS__, $v)); } @@ -139,4 +137,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/ProjectEnvironment.php b/src/Service/CodeBuild/src/ValueObject/ProjectEnvironment.php index a98b97f03..daaaf9afd 100644 --- a/src/Service/CodeBuild/src/ValueObject/ProjectEnvironment.php +++ b/src/Service/CodeBuild/src/ValueObject/ProjectEnvironment.php @@ -5,6 +5,7 @@ use AsyncAws\CodeBuild\Enum\ComputeType; use AsyncAws\CodeBuild\Enum\EnvironmentType; use AsyncAws\CodeBuild\Enum\ImagePullCredentialsType; +use AsyncAws\Core\Exception\InvalidArgument; /** * Information about the build environment of the build project. @@ -141,9 +142,9 @@ final class ProjectEnvironment */ public function __construct(array $input) { - $this->type = $input['type'] ?? null; - $this->image = $input['image'] ?? null; - $this->computeType = $input['computeType'] ?? null; + $this->type = $input['type'] ?? $this->throwException(new InvalidArgument('Missing required field "type".')); + $this->image = $input['image'] ?? $this->throwException(new InvalidArgument('Missing required field "image".')); + $this->computeType = $input['computeType'] ?? $this->throwException(new InvalidArgument('Missing required field "computeType".')); $this->environmentVariables = isset($input['environmentVariables']) ? array_map([EnvironmentVariable::class, 'create'], $input['environmentVariables']) : null; $this->privilegedMode = $input['privilegedMode'] ?? null; $this->certificate = $input['certificate'] ?? null; @@ -219,4 +220,12 @@ public function getType(): string { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/ProjectSource.php b/src/Service/CodeBuild/src/ValueObject/ProjectSource.php index ad642bfee..bb3945efe 100644 --- a/src/Service/CodeBuild/src/ValueObject/ProjectSource.php +++ b/src/Service/CodeBuild/src/ValueObject/ProjectSource.php @@ -140,7 +140,7 @@ final class ProjectSource */ public function __construct(array $input) { - $this->type = $input['type'] ?? null; + $this->type = $input['type'] ?? $this->throwException(new InvalidArgument('Missing required field "type".')); $this->location = $input['location'] ?? null; $this->gitCloneDepth = $input['gitCloneDepth'] ?? null; $this->gitSubmodulesConfig = isset($input['gitSubmodulesConfig']) ? GitSubmodulesConfig::create($input['gitSubmodulesConfig']) : null; @@ -230,9 +230,7 @@ public function getType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!SourceType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "type" for "%s". The value "%s" is not a valid "SourceType".', __CLASS__, $v)); } @@ -267,4 +265,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/ProjectSourceVersion.php b/src/Service/CodeBuild/src/ValueObject/ProjectSourceVersion.php index 73963c556..7de272a93 100644 --- a/src/Service/CodeBuild/src/ValueObject/ProjectSourceVersion.php +++ b/src/Service/CodeBuild/src/ValueObject/ProjectSourceVersion.php @@ -42,8 +42,8 @@ final class ProjectSourceVersion */ public function __construct(array $input) { - $this->sourceIdentifier = $input['sourceIdentifier'] ?? null; - $this->sourceVersion = $input['sourceVersion'] ?? null; + $this->sourceIdentifier = $input['sourceIdentifier'] ?? $this->throwException(new InvalidArgument('Missing required field "sourceIdentifier".')); + $this->sourceVersion = $input['sourceVersion'] ?? $this->throwException(new InvalidArgument('Missing required field "sourceVersion".')); } /** @@ -73,15 +73,19 @@ public function getSourceVersion(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->sourceIdentifier) { - throw new InvalidArgument(sprintf('Missing parameter "sourceIdentifier" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->sourceIdentifier; $payload['sourceIdentifier'] = $v; - if (null === $v = $this->sourceVersion) { - throw new InvalidArgument(sprintf('Missing parameter "sourceVersion" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->sourceVersion; $payload['sourceVersion'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/RegistryCredential.php b/src/Service/CodeBuild/src/ValueObject/RegistryCredential.php index 5dc843e10..74f32cc9c 100644 --- a/src/Service/CodeBuild/src/ValueObject/RegistryCredential.php +++ b/src/Service/CodeBuild/src/ValueObject/RegistryCredential.php @@ -38,8 +38,8 @@ final class RegistryCredential */ public function __construct(array $input) { - $this->credential = $input['credential'] ?? null; - $this->credentialProvider = $input['credentialProvider'] ?? null; + $this->credential = $input['credential'] ?? $this->throwException(new InvalidArgument('Missing required field "credential".')); + $this->credentialProvider = $input['credentialProvider'] ?? $this->throwException(new InvalidArgument('Missing required field "credentialProvider".')); } /** @@ -72,13 +72,9 @@ public function getCredentialProvider(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->credential) { - throw new InvalidArgument(sprintf('Missing parameter "credential" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->credential; $payload['credential'] = $v; - if (null === $v = $this->credentialProvider) { - throw new InvalidArgument(sprintf('Missing parameter "credentialProvider" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->credentialProvider; if (!CredentialProviderType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "credentialProvider" for "%s". The value "%s" is not a valid "CredentialProviderType".', __CLASS__, $v)); } @@ -86,4 +82,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/S3LogsConfig.php b/src/Service/CodeBuild/src/ValueObject/S3LogsConfig.php index cd1ca9f61..8d849a800 100644 --- a/src/Service/CodeBuild/src/ValueObject/S3LogsConfig.php +++ b/src/Service/CodeBuild/src/ValueObject/S3LogsConfig.php @@ -42,7 +42,7 @@ final class S3LogsConfig */ public function __construct(array $input) { - $this->status = $input['status'] ?? null; + $this->status = $input['status'] ?? $this->throwException(new InvalidArgument('Missing required field "status".')); $this->location = $input['location'] ?? null; $this->encryptionDisabled = $input['encryptionDisabled'] ?? null; $this->bucketOwnerAccess = $input['bucketOwnerAccess'] ?? null; @@ -93,9 +93,7 @@ public function getStatus(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->status) { - throw new InvalidArgument(sprintf('Missing parameter "status" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->status; if (!LogsConfigStatusType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "status" for "%s". The value "%s" is not a valid "LogsConfigStatusType".', __CLASS__, $v)); } @@ -115,4 +113,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeBuild/src/ValueObject/SourceAuth.php b/src/Service/CodeBuild/src/ValueObject/SourceAuth.php index dda1141f6..0c722b7d3 100644 --- a/src/Service/CodeBuild/src/ValueObject/SourceAuth.php +++ b/src/Service/CodeBuild/src/ValueObject/SourceAuth.php @@ -32,7 +32,7 @@ final class SourceAuth */ public function __construct(array $input) { - $this->type = $input['type'] ?? null; + $this->type = $input['type'] ?? $this->throwException(new InvalidArgument('Missing required field "type".')); $this->resource = $input['resource'] ?? null; } @@ -66,9 +66,7 @@ public function getType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!SourceAuthType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "type" for "%s". The value "%s" is not a valid "SourceAuthType".', __CLASS__, $v)); } @@ -79,4 +77,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CodeCommit/src/ValueObject/RepositoryTrigger.php b/src/Service/CodeCommit/src/ValueObject/RepositoryTrigger.php index 6f193b258..47dddbe69 100644 --- a/src/Service/CodeCommit/src/ValueObject/RepositoryTrigger.php +++ b/src/Service/CodeCommit/src/ValueObject/RepositoryTrigger.php @@ -52,11 +52,11 @@ final class RepositoryTrigger */ public function __construct(array $input) { - $this->name = $input['name'] ?? null; - $this->destinationArn = $input['destinationArn'] ?? null; + $this->name = $input['name'] ?? $this->throwException(new InvalidArgument('Missing required field "name".')); + $this->destinationArn = $input['destinationArn'] ?? $this->throwException(new InvalidArgument('Missing required field "destinationArn".')); $this->customData = $input['customData'] ?? null; $this->branches = $input['branches'] ?? null; - $this->events = $input['events'] ?? null; + $this->events = $input['events'] ?? $this->throwException(new InvalidArgument('Missing required field "events".')); } /** @@ -96,7 +96,7 @@ public function getDestinationArn(): string */ public function getEvents(): array { - return $this->events ?? []; + return $this->events; } public function getName(): string @@ -110,13 +110,9 @@ public function getName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['name'] = $v; - if (null === $v = $this->destinationArn) { - throw new InvalidArgument(sprintf('Missing parameter "destinationArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->destinationArn; $payload['destinationArn'] = $v; if (null !== $v = $this->customData) { $payload['customData'] = $v; @@ -129,9 +125,7 @@ public function requestBody(): array $payload['branches'][$index] = $listValue; } } - if (null === $v = $this->events) { - throw new InvalidArgument(sprintf('Missing parameter "events" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->events; $index = -1; $payload['events'] = []; @@ -145,4 +139,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CognitoIdentityProvider/src/ValueObject/AttributeType.php b/src/Service/CognitoIdentityProvider/src/ValueObject/AttributeType.php index bfa92fa99..beb7d6dc0 100644 --- a/src/Service/CognitoIdentityProvider/src/ValueObject/AttributeType.php +++ b/src/Service/CognitoIdentityProvider/src/ValueObject/AttributeType.php @@ -27,7 +27,7 @@ final class AttributeType */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); $this->value = $input['Value'] ?? null; } @@ -58,9 +58,7 @@ public function getValue(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; if (null !== $v = $this->value) { $payload['Value'] = $v; @@ -68,4 +66,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/CognitoIdentityProvider/src/ValueObject/ContextDataType.php b/src/Service/CognitoIdentityProvider/src/ValueObject/ContextDataType.php index c76e8649c..b2fa37608 100644 --- a/src/Service/CognitoIdentityProvider/src/ValueObject/ContextDataType.php +++ b/src/Service/CognitoIdentityProvider/src/ValueObject/ContextDataType.php @@ -48,10 +48,10 @@ final class ContextDataType */ public function __construct(array $input) { - $this->ipAddress = $input['IpAddress'] ?? null; - $this->serverName = $input['ServerName'] ?? null; - $this->serverPath = $input['ServerPath'] ?? null; - $this->httpHeaders = isset($input['HttpHeaders']) ? array_map([HttpHeader::class, 'create'], $input['HttpHeaders']) : null; + $this->ipAddress = $input['IpAddress'] ?? $this->throwException(new InvalidArgument('Missing required field "IpAddress".')); + $this->serverName = $input['ServerName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServerName".')); + $this->serverPath = $input['ServerPath'] ?? $this->throwException(new InvalidArgument('Missing required field "ServerPath".')); + $this->httpHeaders = isset($input['HttpHeaders']) ? array_map([HttpHeader::class, 'create'], $input['HttpHeaders']) : $this->throwException(new InvalidArgument('Missing required field "HttpHeaders".')); $this->encodedData = $input['EncodedData'] ?? null; } @@ -79,7 +79,7 @@ public function getEncodedData(): ?string */ public function getHttpHeaders(): array { - return $this->httpHeaders ?? []; + return $this->httpHeaders; } public function getIpAddress(): string @@ -103,21 +103,13 @@ public function getServerPath(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->ipAddress) { - throw new InvalidArgument(sprintf('Missing parameter "IpAddress" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->ipAddress; $payload['IpAddress'] = $v; - if (null === $v = $this->serverName) { - throw new InvalidArgument(sprintf('Missing parameter "ServerName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->serverName; $payload['ServerName'] = $v; - if (null === $v = $this->serverPath) { - throw new InvalidArgument(sprintf('Missing parameter "ServerPath" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->serverPath; $payload['ServerPath'] = $v; - if (null === $v = $this->httpHeaders) { - throw new InvalidArgument(sprintf('Missing parameter "HttpHeaders" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->httpHeaders; $index = -1; $payload['HttpHeaders'] = []; @@ -132,4 +124,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/AttributeDefinition.php b/src/Service/DynamoDb/src/ValueObject/AttributeDefinition.php index 00f20bf24..fe532378e 100644 --- a/src/Service/DynamoDb/src/ValueObject/AttributeDefinition.php +++ b/src/Service/DynamoDb/src/ValueObject/AttributeDefinition.php @@ -32,8 +32,8 @@ final class AttributeDefinition */ public function __construct(array $input) { - $this->attributeName = $input['AttributeName'] ?? null; - $this->attributeType = $input['AttributeType'] ?? null; + $this->attributeName = $input['AttributeName'] ?? $this->throwException(new InvalidArgument('Missing required field "AttributeName".')); + $this->attributeType = $input['AttributeType'] ?? $this->throwException(new InvalidArgument('Missing required field "AttributeType".')); } /** @@ -66,13 +66,9 @@ public function getAttributeType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->attributeName) { - throw new InvalidArgument(sprintf('Missing parameter "AttributeName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->attributeName; $payload['AttributeName'] = $v; - if (null === $v = $this->attributeType) { - throw new InvalidArgument(sprintf('Missing parameter "AttributeType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->attributeType; if (!ScalarAttributeType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "AttributeType" for "%s". The value "%s" is not a valid "ScalarAttributeType".', __CLASS__, $v)); } @@ -80,4 +76,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Condition.php b/src/Service/DynamoDb/src/ValueObject/Condition.php index 876868c69..974b729bb 100644 --- a/src/Service/DynamoDb/src/ValueObject/Condition.php +++ b/src/Service/DynamoDb/src/ValueObject/Condition.php @@ -146,7 +146,7 @@ final class Condition public function __construct(array $input) { $this->attributeValueList = isset($input['AttributeValueList']) ? array_map([AttributeValue::class, 'create'], $input['AttributeValueList']) : null; - $this->comparisonOperator = $input['ComparisonOperator'] ?? null; + $this->comparisonOperator = $input['ComparisonOperator'] ?? $this->throwException(new InvalidArgument('Missing required field "ComparisonOperator".')); } /** @@ -190,9 +190,7 @@ public function requestBody(): array $payload['AttributeValueList'][$index] = $listValue->requestBody(); } } - if (null === $v = $this->comparisonOperator) { - throw new InvalidArgument(sprintf('Missing parameter "ComparisonOperator" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->comparisonOperator; if (!ComparisonOperator::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "ComparisonOperator" for "%s". The value "%s" is not a valid "ComparisonOperator".', __CLASS__, $v)); } @@ -200,4 +198,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/ConditionCheck.php b/src/Service/DynamoDb/src/ValueObject/ConditionCheck.php index c1a762942..57f86f044 100644 --- a/src/Service/DynamoDb/src/ValueObject/ConditionCheck.php +++ b/src/Service/DynamoDb/src/ValueObject/ConditionCheck.php @@ -63,9 +63,9 @@ final class ConditionCheck */ public function __construct(array $input) { - $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : null; - $this->tableName = $input['TableName'] ?? null; - $this->conditionExpression = $input['ConditionExpression'] ?? null; + $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->tableName = $input['TableName'] ?? $this->throwException(new InvalidArgument('Missing required field "TableName".')); + $this->conditionExpression = $input['ConditionExpression'] ?? $this->throwException(new InvalidArgument('Missing required field "ConditionExpression".')); $this->expressionAttributeNames = $input['ExpressionAttributeNames'] ?? null; $this->expressionAttributeValues = isset($input['ExpressionAttributeValues']) ? array_map([AttributeValue::class, 'create'], $input['ExpressionAttributeValues']) : null; $this->returnValuesOnConditionCheckFailure = $input['ReturnValuesOnConditionCheckFailure'] ?? null; @@ -112,7 +112,7 @@ public function getExpressionAttributeValues(): array */ public function getKey(): array { - return $this->key ?? []; + return $this->key; } /** @@ -134,9 +134,7 @@ public function getTableName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; if (empty($v)) { $payload['Key'] = new \stdClass(); @@ -146,13 +144,9 @@ public function requestBody(): array $payload['Key'][$name] = $mv->requestBody(); } } - if (null === $v = $this->tableName) { - throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tableName; $payload['TableName'] = $v; - if (null === $v = $this->conditionExpression) { - throw new InvalidArgument(sprintf('Missing parameter "ConditionExpression" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->conditionExpression; $payload['ConditionExpression'] = $v; if (null !== $v = $this->expressionAttributeNames) { if (empty($v)) { @@ -183,4 +177,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/CreateGlobalSecondaryIndexAction.php b/src/Service/DynamoDb/src/ValueObject/CreateGlobalSecondaryIndexAction.php index 99a5f0d39..24c9c3678 100644 --- a/src/Service/DynamoDb/src/ValueObject/CreateGlobalSecondaryIndexAction.php +++ b/src/Service/DynamoDb/src/ValueObject/CreateGlobalSecondaryIndexAction.php @@ -45,9 +45,9 @@ final class CreateGlobalSecondaryIndexAction */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; - $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : null; - $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); + $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : $this->throwException(new InvalidArgument('Missing required field "KeySchema".')); + $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : $this->throwException(new InvalidArgument('Missing required field "Projection".')); $this->provisionedThroughput = isset($input['ProvisionedThroughput']) ? ProvisionedThroughput::create($input['ProvisionedThroughput']) : null; } @@ -74,7 +74,7 @@ public function getIndexName(): string */ public function getKeySchema(): array { - return $this->keySchema ?? []; + return $this->keySchema; } public function getProjection(): Projection @@ -93,13 +93,9 @@ public function getProvisionedThroughput(): ?ProvisionedThroughput public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; - if (null === $v = $this->keySchema) { - throw new InvalidArgument(sprintf('Missing parameter "KeySchema" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->keySchema; $index = -1; $payload['KeySchema'] = []; @@ -108,9 +104,7 @@ public function requestBody(): array $payload['KeySchema'][$index] = $listValue->requestBody(); } - if (null === $v = $this->projection) { - throw new InvalidArgument(sprintf('Missing parameter "Projection" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->projection; $payload['Projection'] = $v->requestBody(); if (null !== $v = $this->provisionedThroughput) { $payload['ProvisionedThroughput'] = $v->requestBody(); @@ -118,4 +112,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/CreateReplicationGroupMemberAction.php b/src/Service/DynamoDb/src/ValueObject/CreateReplicationGroupMemberAction.php index ac013fce7..65bda4039 100644 --- a/src/Service/DynamoDb/src/ValueObject/CreateReplicationGroupMemberAction.php +++ b/src/Service/DynamoDb/src/ValueObject/CreateReplicationGroupMemberAction.php @@ -48,7 +48,7 @@ final class CreateReplicationGroupMemberAction */ public function __construct(array $input) { - $this->regionName = $input['RegionName'] ?? null; + $this->regionName = $input['RegionName'] ?? $this->throwException(new InvalidArgument('Missing required field "RegionName".')); $this->kmsMasterKeyId = $input['KMSMasterKeyId'] ?? null; $this->provisionedThroughputOverride = isset($input['ProvisionedThroughputOverride']) ? ProvisionedThroughputOverride::create($input['ProvisionedThroughputOverride']) : null; $this->globalSecondaryIndexes = isset($input['GlobalSecondaryIndexes']) ? array_map([ReplicaGlobalSecondaryIndex::class, 'create'], $input['GlobalSecondaryIndexes']) : null; @@ -106,9 +106,7 @@ public function getTableClassOverride(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->regionName) { - throw new InvalidArgument(sprintf('Missing parameter "RegionName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->regionName; $payload['RegionName'] = $v; if (null !== $v = $this->kmsMasterKeyId) { $payload['KMSMasterKeyId'] = $v; @@ -133,4 +131,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Delete.php b/src/Service/DynamoDb/src/ValueObject/Delete.php index 230da3a9b..f6ad74a25 100644 --- a/src/Service/DynamoDb/src/ValueObject/Delete.php +++ b/src/Service/DynamoDb/src/ValueObject/Delete.php @@ -53,8 +53,8 @@ final class Delete */ public function __construct(array $input) { - $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : null; - $this->tableName = $input['TableName'] ?? null; + $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->tableName = $input['TableName'] ?? $this->throwException(new InvalidArgument('Missing required field "TableName".')); $this->conditionExpression = $input['ConditionExpression'] ?? null; $this->expressionAttributeNames = $input['ExpressionAttributeNames'] ?? null; $this->expressionAttributeValues = isset($input['ExpressionAttributeValues']) ? array_map([AttributeValue::class, 'create'], $input['ExpressionAttributeValues']) : null; @@ -102,7 +102,7 @@ public function getExpressionAttributeValues(): array */ public function getKey(): array { - return $this->key ?? []; + return $this->key; } /** @@ -124,9 +124,7 @@ public function getTableName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; if (empty($v)) { $payload['Key'] = new \stdClass(); @@ -136,9 +134,7 @@ public function requestBody(): array $payload['Key'][$name] = $mv->requestBody(); } } - if (null === $v = $this->tableName) { - throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tableName; $payload['TableName'] = $v; if (null !== $v = $this->conditionExpression) { $payload['ConditionExpression'] = $v; @@ -172,4 +168,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/DeleteGlobalSecondaryIndexAction.php b/src/Service/DynamoDb/src/ValueObject/DeleteGlobalSecondaryIndexAction.php index 526a3eb8b..65c879650 100644 --- a/src/Service/DynamoDb/src/ValueObject/DeleteGlobalSecondaryIndexAction.php +++ b/src/Service/DynamoDb/src/ValueObject/DeleteGlobalSecondaryIndexAction.php @@ -21,7 +21,7 @@ final class DeleteGlobalSecondaryIndexAction */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); } /** @@ -45,11 +45,17 @@ public function getIndexName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/DeleteReplicationGroupMemberAction.php b/src/Service/DynamoDb/src/ValueObject/DeleteReplicationGroupMemberAction.php index 91df024cb..88c0e97cf 100644 --- a/src/Service/DynamoDb/src/ValueObject/DeleteReplicationGroupMemberAction.php +++ b/src/Service/DynamoDb/src/ValueObject/DeleteReplicationGroupMemberAction.php @@ -21,7 +21,7 @@ final class DeleteReplicationGroupMemberAction */ public function __construct(array $input) { - $this->regionName = $input['RegionName'] ?? null; + $this->regionName = $input['RegionName'] ?? $this->throwException(new InvalidArgument('Missing required field "RegionName".')); } /** @@ -45,11 +45,17 @@ public function getRegionName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->regionName) { - throw new InvalidArgument(sprintf('Missing parameter "RegionName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->regionName; $payload['RegionName'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/DeleteRequest.php b/src/Service/DynamoDb/src/ValueObject/DeleteRequest.php index 6b4d8a7cc..2cc25a6ce 100644 --- a/src/Service/DynamoDb/src/ValueObject/DeleteRequest.php +++ b/src/Service/DynamoDb/src/ValueObject/DeleteRequest.php @@ -22,7 +22,7 @@ final class DeleteRequest */ public function __construct(array $input) { - $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : null; + $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : $this->throwException(new InvalidArgument('Missing required field "Key".')); } /** @@ -40,7 +40,7 @@ public static function create($input): self */ public function getKey(): array { - return $this->key ?? []; + return $this->key; } /** @@ -49,9 +49,7 @@ public function getKey(): array public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; if (empty($v)) { $payload['Key'] = new \stdClass(); @@ -64,4 +62,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Endpoint.php b/src/Service/DynamoDb/src/ValueObject/Endpoint.php index 39c0150f4..bedeac374 100644 --- a/src/Service/DynamoDb/src/ValueObject/Endpoint.php +++ b/src/Service/DynamoDb/src/ValueObject/Endpoint.php @@ -3,6 +3,7 @@ namespace AsyncAws\DynamoDb\ValueObject; use AsyncAws\Core\EndpointDiscovery\EndpointInterface; +use AsyncAws\Core\Exception\InvalidArgument; /** * An endpoint information details. @@ -27,8 +28,8 @@ final class Endpoint implements EndpointInterface */ public function __construct(array $input) { - $this->address = $input['Address'] ?? null; - $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? null; + $this->address = $input['Address'] ?? $this->throwException(new InvalidArgument('Missing required field "Address".')); + $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? $this->throwException(new InvalidArgument('Missing required field "CachePeriodInMinutes".')); } /** @@ -51,4 +52,12 @@ public function getCachePeriodInMinutes(): int { return $this->cachePeriodInMinutes; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/GlobalSecondaryIndex.php b/src/Service/DynamoDb/src/ValueObject/GlobalSecondaryIndex.php index 5451eb334..56187402b 100644 --- a/src/Service/DynamoDb/src/ValueObject/GlobalSecondaryIndex.php +++ b/src/Service/DynamoDb/src/ValueObject/GlobalSecondaryIndex.php @@ -56,9 +56,9 @@ final class GlobalSecondaryIndex */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; - $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : null; - $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); + $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : $this->throwException(new InvalidArgument('Missing required field "KeySchema".')); + $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : $this->throwException(new InvalidArgument('Missing required field "Projection".')); $this->provisionedThroughput = isset($input['ProvisionedThroughput']) ? ProvisionedThroughput::create($input['ProvisionedThroughput']) : null; } @@ -85,7 +85,7 @@ public function getIndexName(): string */ public function getKeySchema(): array { - return $this->keySchema ?? []; + return $this->keySchema; } public function getProjection(): Projection @@ -104,13 +104,9 @@ public function getProvisionedThroughput(): ?ProvisionedThroughput public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; - if (null === $v = $this->keySchema) { - throw new InvalidArgument(sprintf('Missing parameter "KeySchema" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->keySchema; $index = -1; $payload['KeySchema'] = []; @@ -119,9 +115,7 @@ public function requestBody(): array $payload['KeySchema'][$index] = $listValue->requestBody(); } - if (null === $v = $this->projection) { - throw new InvalidArgument(sprintf('Missing parameter "Projection" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->projection; $payload['Projection'] = $v->requestBody(); if (null !== $v = $this->provisionedThroughput) { $payload['ProvisionedThroughput'] = $v->requestBody(); @@ -129,4 +123,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/KeySchemaElement.php b/src/Service/DynamoDb/src/ValueObject/KeySchemaElement.php index 574db8857..d88570416 100644 --- a/src/Service/DynamoDb/src/ValueObject/KeySchemaElement.php +++ b/src/Service/DynamoDb/src/ValueObject/KeySchemaElement.php @@ -46,8 +46,8 @@ final class KeySchemaElement */ public function __construct(array $input) { - $this->attributeName = $input['AttributeName'] ?? null; - $this->keyType = $input['KeyType'] ?? null; + $this->attributeName = $input['AttributeName'] ?? $this->throwException(new InvalidArgument('Missing required field "AttributeName".')); + $this->keyType = $input['KeyType'] ?? $this->throwException(new InvalidArgument('Missing required field "KeyType".')); } /** @@ -80,13 +80,9 @@ public function getKeyType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->attributeName) { - throw new InvalidArgument(sprintf('Missing parameter "AttributeName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->attributeName; $payload['AttributeName'] = $v; - if (null === $v = $this->keyType) { - throw new InvalidArgument(sprintf('Missing parameter "KeyType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->keyType; if (!KeyType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "KeyType" for "%s". The value "%s" is not a valid "KeyType".', __CLASS__, $v)); } @@ -94,4 +90,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/KeysAndAttributes.php b/src/Service/DynamoDb/src/ValueObject/KeysAndAttributes.php index 3b03df9a0..fba385e45 100644 --- a/src/Service/DynamoDb/src/ValueObject/KeysAndAttributes.php +++ b/src/Service/DynamoDb/src/ValueObject/KeysAndAttributes.php @@ -90,7 +90,7 @@ final class KeysAndAttributes */ public function __construct(array $input) { - $this->keys = $input['Keys'] ?? null; + $this->keys = $input['Keys'] ?? $this->throwException(new InvalidArgument('Missing required field "Keys".')); $this->attributesToGet = $input['AttributesToGet'] ?? null; $this->consistentRead = $input['ConsistentRead'] ?? null; $this->projectionExpression = $input['ProjectionExpression'] ?? null; @@ -137,7 +137,7 @@ public function getExpressionAttributeNames(): array */ public function getKeys(): array { - return $this->keys ?? []; + return $this->keys; } public function getProjectionExpression(): ?string @@ -151,9 +151,7 @@ public function getProjectionExpression(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->keys) { - throw new InvalidArgument(sprintf('Missing parameter "Keys" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->keys; $index = -1; $payload['Keys'] = []; @@ -197,4 +195,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/LocalSecondaryIndex.php b/src/Service/DynamoDb/src/ValueObject/LocalSecondaryIndex.php index 86975f53f..57d05c813 100644 --- a/src/Service/DynamoDb/src/ValueObject/LocalSecondaryIndex.php +++ b/src/Service/DynamoDb/src/ValueObject/LocalSecondaryIndex.php @@ -45,9 +45,9 @@ final class LocalSecondaryIndex */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; - $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : null; - $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); + $this->keySchema = isset($input['KeySchema']) ? array_map([KeySchemaElement::class, 'create'], $input['KeySchema']) : $this->throwException(new InvalidArgument('Missing required field "KeySchema".')); + $this->projection = isset($input['Projection']) ? Projection::create($input['Projection']) : $this->throwException(new InvalidArgument('Missing required field "Projection".')); } /** @@ -72,7 +72,7 @@ public function getIndexName(): string */ public function getKeySchema(): array { - return $this->keySchema ?? []; + return $this->keySchema; } public function getProjection(): Projection @@ -86,13 +86,9 @@ public function getProjection(): Projection public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; - if (null === $v = $this->keySchema) { - throw new InvalidArgument(sprintf('Missing parameter "KeySchema" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->keySchema; $index = -1; $payload['KeySchema'] = []; @@ -101,11 +97,17 @@ public function requestBody(): array $payload['KeySchema'][$index] = $listValue->requestBody(); } - if (null === $v = $this->projection) { - throw new InvalidArgument(sprintf('Missing parameter "Projection" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->projection; $payload['Projection'] = $v->requestBody(); return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/ProvisionedThroughput.php b/src/Service/DynamoDb/src/ValueObject/ProvisionedThroughput.php index 815744eb6..7c98f7a36 100644 --- a/src/Service/DynamoDb/src/ValueObject/ProvisionedThroughput.php +++ b/src/Service/DynamoDb/src/ValueObject/ProvisionedThroughput.php @@ -43,8 +43,8 @@ final class ProvisionedThroughput */ public function __construct(array $input) { - $this->readCapacityUnits = $input['ReadCapacityUnits'] ?? null; - $this->writeCapacityUnits = $input['WriteCapacityUnits'] ?? null; + $this->readCapacityUnits = $input['ReadCapacityUnits'] ?? $this->throwException(new InvalidArgument('Missing required field "ReadCapacityUnits".')); + $this->writeCapacityUnits = $input['WriteCapacityUnits'] ?? $this->throwException(new InvalidArgument('Missing required field "WriteCapacityUnits".')); } /** @@ -74,15 +74,19 @@ public function getWriteCapacityUnits(): int public function requestBody(): array { $payload = []; - if (null === $v = $this->readCapacityUnits) { - throw new InvalidArgument(sprintf('Missing parameter "ReadCapacityUnits" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->readCapacityUnits; $payload['ReadCapacityUnits'] = $v; - if (null === $v = $this->writeCapacityUnits) { - throw new InvalidArgument(sprintf('Missing parameter "WriteCapacityUnits" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->writeCapacityUnits; $payload['WriteCapacityUnits'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Put.php b/src/Service/DynamoDb/src/ValueObject/Put.php index f1d2fddac..7e276bf06 100644 --- a/src/Service/DynamoDb/src/ValueObject/Put.php +++ b/src/Service/DynamoDb/src/ValueObject/Put.php @@ -56,8 +56,8 @@ final class Put */ public function __construct(array $input) { - $this->item = isset($input['Item']) ? array_map([AttributeValue::class, 'create'], $input['Item']) : null; - $this->tableName = $input['TableName'] ?? null; + $this->item = isset($input['Item']) ? array_map([AttributeValue::class, 'create'], $input['Item']) : $this->throwException(new InvalidArgument('Missing required field "Item".')); + $this->tableName = $input['TableName'] ?? $this->throwException(new InvalidArgument('Missing required field "TableName".')); $this->conditionExpression = $input['ConditionExpression'] ?? null; $this->expressionAttributeNames = $input['ExpressionAttributeNames'] ?? null; $this->expressionAttributeValues = isset($input['ExpressionAttributeValues']) ? array_map([AttributeValue::class, 'create'], $input['ExpressionAttributeValues']) : null; @@ -105,7 +105,7 @@ public function getExpressionAttributeValues(): array */ public function getItem(): array { - return $this->item ?? []; + return $this->item; } /** @@ -127,9 +127,7 @@ public function getTableName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->item) { - throw new InvalidArgument(sprintf('Missing parameter "Item" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->item; if (empty($v)) { $payload['Item'] = new \stdClass(); @@ -139,9 +137,7 @@ public function requestBody(): array $payload['Item'][$name] = $mv->requestBody(); } } - if (null === $v = $this->tableName) { - throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tableName; $payload['TableName'] = $v; if (null !== $v = $this->conditionExpression) { $payload['ConditionExpression'] = $v; @@ -175,4 +171,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/PutRequest.php b/src/Service/DynamoDb/src/ValueObject/PutRequest.php index 8eb90cdbd..650d38384 100644 --- a/src/Service/DynamoDb/src/ValueObject/PutRequest.php +++ b/src/Service/DynamoDb/src/ValueObject/PutRequest.php @@ -24,7 +24,7 @@ final class PutRequest */ public function __construct(array $input) { - $this->item = isset($input['Item']) ? array_map([AttributeValue::class, 'create'], $input['Item']) : null; + $this->item = isset($input['Item']) ? array_map([AttributeValue::class, 'create'], $input['Item']) : $this->throwException(new InvalidArgument('Missing required field "Item".')); } /** @@ -42,7 +42,7 @@ public static function create($input): self */ public function getItem(): array { - return $this->item ?? []; + return $this->item; } /** @@ -51,9 +51,7 @@ public function getItem(): array public function requestBody(): array { $payload = []; - if (null === $v = $this->item) { - throw new InvalidArgument(sprintf('Missing parameter "Item" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->item; if (empty($v)) { $payload['Item'] = new \stdClass(); @@ -66,4 +64,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/ReplicaGlobalSecondaryIndex.php b/src/Service/DynamoDb/src/ValueObject/ReplicaGlobalSecondaryIndex.php index 85cc973a5..8228b95c6 100644 --- a/src/Service/DynamoDb/src/ValueObject/ReplicaGlobalSecondaryIndex.php +++ b/src/Service/DynamoDb/src/ValueObject/ReplicaGlobalSecondaryIndex.php @@ -28,7 +28,7 @@ final class ReplicaGlobalSecondaryIndex */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); $this->provisionedThroughputOverride = isset($input['ProvisionedThroughputOverride']) ? ProvisionedThroughputOverride::create($input['ProvisionedThroughputOverride']) : null; } @@ -59,9 +59,7 @@ public function getProvisionedThroughputOverride(): ?ProvisionedThroughputOverri public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; if (null !== $v = $this->provisionedThroughputOverride) { $payload['ProvisionedThroughputOverride'] = $v->requestBody(); @@ -69,4 +67,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/RestoreSummary.php b/src/Service/DynamoDb/src/ValueObject/RestoreSummary.php index 2982db324..fa1b564d7 100644 --- a/src/Service/DynamoDb/src/ValueObject/RestoreSummary.php +++ b/src/Service/DynamoDb/src/ValueObject/RestoreSummary.php @@ -2,6 +2,8 @@ namespace AsyncAws\DynamoDb\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains details for the restore. */ @@ -39,8 +41,8 @@ public function __construct(array $input) { $this->sourceBackupArn = $input['SourceBackupArn'] ?? null; $this->sourceTableArn = $input['SourceTableArn'] ?? null; - $this->restoreDateTime = $input['RestoreDateTime'] ?? null; - $this->restoreInProgress = $input['RestoreInProgress'] ?? null; + $this->restoreDateTime = $input['RestoreDateTime'] ?? $this->throwException(new InvalidArgument('Missing required field "RestoreDateTime".')); + $this->restoreInProgress = $input['RestoreInProgress'] ?? $this->throwException(new InvalidArgument('Missing required field "RestoreInProgress".')); } /** @@ -75,4 +77,12 @@ public function getSourceTableArn(): ?string { return $this->sourceTableArn; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/StreamSpecification.php b/src/Service/DynamoDb/src/ValueObject/StreamSpecification.php index 7b26cb86e..09def8ee1 100644 --- a/src/Service/DynamoDb/src/ValueObject/StreamSpecification.php +++ b/src/Service/DynamoDb/src/ValueObject/StreamSpecification.php @@ -34,7 +34,7 @@ final class StreamSpecification */ public function __construct(array $input) { - $this->streamEnabled = $input['StreamEnabled'] ?? null; + $this->streamEnabled = $input['StreamEnabled'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamEnabled".')); $this->streamViewType = $input['StreamViewType'] ?? null; } @@ -68,9 +68,7 @@ public function getStreamViewType(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->streamEnabled) { - throw new InvalidArgument(sprintf('Missing parameter "StreamEnabled" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->streamEnabled; $payload['StreamEnabled'] = (bool) $v; if (null !== $v = $this->streamViewType) { if (!StreamViewType::exists($v)) { @@ -81,4 +79,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Tag.php b/src/Service/DynamoDb/src/ValueObject/Tag.php index daa8c64bb..19ffacaf5 100644 --- a/src/Service/DynamoDb/src/ValueObject/Tag.php +++ b/src/Service/DynamoDb/src/ValueObject/Tag.php @@ -37,8 +37,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -68,15 +68,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/TimeToLiveSpecification.php b/src/Service/DynamoDb/src/ValueObject/TimeToLiveSpecification.php index 23989c732..7ed7e4a9b 100644 --- a/src/Service/DynamoDb/src/ValueObject/TimeToLiveSpecification.php +++ b/src/Service/DynamoDb/src/ValueObject/TimeToLiveSpecification.php @@ -27,8 +27,8 @@ final class TimeToLiveSpecification */ public function __construct(array $input) { - $this->enabled = $input['Enabled'] ?? null; - $this->attributeName = $input['AttributeName'] ?? null; + $this->enabled = $input['Enabled'] ?? $this->throwException(new InvalidArgument('Missing required field "Enabled".')); + $this->attributeName = $input['AttributeName'] ?? $this->throwException(new InvalidArgument('Missing required field "AttributeName".')); } /** @@ -58,15 +58,19 @@ public function getEnabled(): bool public function requestBody(): array { $payload = []; - if (null === $v = $this->enabled) { - throw new InvalidArgument(sprintf('Missing parameter "Enabled" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->enabled; $payload['Enabled'] = (bool) $v; - if (null === $v = $this->attributeName) { - throw new InvalidArgument(sprintf('Missing parameter "AttributeName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->attributeName; $payload['AttributeName'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/Update.php b/src/Service/DynamoDb/src/ValueObject/Update.php index 364a3ab7e..90702eb86 100644 --- a/src/Service/DynamoDb/src/ValueObject/Update.php +++ b/src/Service/DynamoDb/src/ValueObject/Update.php @@ -60,9 +60,9 @@ final class Update */ public function __construct(array $input) { - $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : null; - $this->updateExpression = $input['UpdateExpression'] ?? null; - $this->tableName = $input['TableName'] ?? null; + $this->key = isset($input['Key']) ? array_map([AttributeValue::class, 'create'], $input['Key']) : $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->updateExpression = $input['UpdateExpression'] ?? $this->throwException(new InvalidArgument('Missing required field "UpdateExpression".')); + $this->tableName = $input['TableName'] ?? $this->throwException(new InvalidArgument('Missing required field "TableName".')); $this->conditionExpression = $input['ConditionExpression'] ?? null; $this->expressionAttributeNames = $input['ExpressionAttributeNames'] ?? null; $this->expressionAttributeValues = isset($input['ExpressionAttributeValues']) ? array_map([AttributeValue::class, 'create'], $input['ExpressionAttributeValues']) : null; @@ -111,7 +111,7 @@ public function getExpressionAttributeValues(): array */ public function getKey(): array { - return $this->key ?? []; + return $this->key; } /** @@ -138,9 +138,7 @@ public function getUpdateExpression(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; if (empty($v)) { $payload['Key'] = new \stdClass(); @@ -150,13 +148,9 @@ public function requestBody(): array $payload['Key'][$name] = $mv->requestBody(); } } - if (null === $v = $this->updateExpression) { - throw new InvalidArgument(sprintf('Missing parameter "UpdateExpression" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->updateExpression; $payload['UpdateExpression'] = $v; - if (null === $v = $this->tableName) { - throw new InvalidArgument(sprintf('Missing parameter "TableName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tableName; $payload['TableName'] = $v; if (null !== $v = $this->conditionExpression) { $payload['ConditionExpression'] = $v; @@ -190,4 +184,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/UpdateGlobalSecondaryIndexAction.php b/src/Service/DynamoDb/src/ValueObject/UpdateGlobalSecondaryIndexAction.php index ea97132aa..b3b2b3712 100644 --- a/src/Service/DynamoDb/src/ValueObject/UpdateGlobalSecondaryIndexAction.php +++ b/src/Service/DynamoDb/src/ValueObject/UpdateGlobalSecondaryIndexAction.php @@ -32,8 +32,8 @@ final class UpdateGlobalSecondaryIndexAction */ public function __construct(array $input) { - $this->indexName = $input['IndexName'] ?? null; - $this->provisionedThroughput = isset($input['ProvisionedThroughput']) ? ProvisionedThroughput::create($input['ProvisionedThroughput']) : null; + $this->indexName = $input['IndexName'] ?? $this->throwException(new InvalidArgument('Missing required field "IndexName".')); + $this->provisionedThroughput = isset($input['ProvisionedThroughput']) ? ProvisionedThroughput::create($input['ProvisionedThroughput']) : $this->throwException(new InvalidArgument('Missing required field "ProvisionedThroughput".')); } /** @@ -63,15 +63,19 @@ public function getProvisionedThroughput(): ProvisionedThroughput public function requestBody(): array { $payload = []; - if (null === $v = $this->indexName) { - throw new InvalidArgument(sprintf('Missing parameter "IndexName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->indexName; $payload['IndexName'] = $v; - if (null === $v = $this->provisionedThroughput) { - throw new InvalidArgument(sprintf('Missing parameter "ProvisionedThroughput" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->provisionedThroughput; $payload['ProvisionedThroughput'] = $v->requestBody(); return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/DynamoDb/src/ValueObject/UpdateReplicationGroupMemberAction.php b/src/Service/DynamoDb/src/ValueObject/UpdateReplicationGroupMemberAction.php index c8872c399..213800d4a 100644 --- a/src/Service/DynamoDb/src/ValueObject/UpdateReplicationGroupMemberAction.php +++ b/src/Service/DynamoDb/src/ValueObject/UpdateReplicationGroupMemberAction.php @@ -48,7 +48,7 @@ final class UpdateReplicationGroupMemberAction */ public function __construct(array $input) { - $this->regionName = $input['RegionName'] ?? null; + $this->regionName = $input['RegionName'] ?? $this->throwException(new InvalidArgument('Missing required field "RegionName".')); $this->kmsMasterKeyId = $input['KMSMasterKeyId'] ?? null; $this->provisionedThroughputOverride = isset($input['ProvisionedThroughputOverride']) ? ProvisionedThroughputOverride::create($input['ProvisionedThroughputOverride']) : null; $this->globalSecondaryIndexes = isset($input['GlobalSecondaryIndexes']) ? array_map([ReplicaGlobalSecondaryIndex::class, 'create'], $input['GlobalSecondaryIndexes']) : null; @@ -106,9 +106,7 @@ public function getTableClassOverride(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->regionName) { - throw new InvalidArgument(sprintf('Missing parameter "RegionName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->regionName; $payload['RegionName'] = $v; if (null !== $v = $this->kmsMasterKeyId) { $payload['KMSMasterKeyId'] = $v; @@ -133,4 +131,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Firehose/src/ValueObject/Record.php b/src/Service/Firehose/src/ValueObject/Record.php index 04559482f..ea9216ec2 100644 --- a/src/Service/Firehose/src/ValueObject/Record.php +++ b/src/Service/Firehose/src/ValueObject/Record.php @@ -22,7 +22,7 @@ final class Record */ public function __construct(array $input) { - $this->data = $input['Data'] ?? null; + $this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".')); } /** @@ -46,11 +46,17 @@ public function getData(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->data) { - throw new InvalidArgument(sprintf('Missing parameter "Data" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->data; $payload['Data'] = base64_encode($v); return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iam/src/ValueObject/AccessKey.php b/src/Service/Iam/src/ValueObject/AccessKey.php index 47453a6cb..2ed20a753 100644 --- a/src/Service/Iam/src/ValueObject/AccessKey.php +++ b/src/Service/Iam/src/ValueObject/AccessKey.php @@ -2,6 +2,7 @@ namespace AsyncAws\Iam\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Iam\Enum\StatusType; /** @@ -51,10 +52,10 @@ final class AccessKey */ public function __construct(array $input) { - $this->userName = $input['UserName'] ?? null; - $this->accessKeyId = $input['AccessKeyId'] ?? null; - $this->status = $input['Status'] ?? null; - $this->secretAccessKey = $input['SecretAccessKey'] ?? null; + $this->userName = $input['UserName'] ?? $this->throwException(new InvalidArgument('Missing required field "UserName".')); + $this->accessKeyId = $input['AccessKeyId'] ?? $this->throwException(new InvalidArgument('Missing required field "AccessKeyId".')); + $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".')); + $this->secretAccessKey = $input['SecretAccessKey'] ?? $this->throwException(new InvalidArgument('Missing required field "SecretAccessKey".')); $this->createDate = $input['CreateDate'] ?? null; } @@ -99,4 +100,12 @@ public function getUserName(): string { return $this->userName; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iam/src/ValueObject/ServiceSpecificCredential.php b/src/Service/Iam/src/ValueObject/ServiceSpecificCredential.php index fa19a4ff3..8c929222a 100644 --- a/src/Service/Iam/src/ValueObject/ServiceSpecificCredential.php +++ b/src/Service/Iam/src/ValueObject/ServiceSpecificCredential.php @@ -2,6 +2,7 @@ namespace AsyncAws\Iam\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Iam\Enum\StatusType; /** @@ -62,13 +63,13 @@ final class ServiceSpecificCredential */ public function __construct(array $input) { - $this->createDate = $input['CreateDate'] ?? null; - $this->serviceName = $input['ServiceName'] ?? null; - $this->serviceUserName = $input['ServiceUserName'] ?? null; - $this->servicePassword = $input['ServicePassword'] ?? null; - $this->serviceSpecificCredentialId = $input['ServiceSpecificCredentialId'] ?? null; - $this->userName = $input['UserName'] ?? null; - $this->status = $input['Status'] ?? null; + $this->createDate = $input['CreateDate'] ?? $this->throwException(new InvalidArgument('Missing required field "CreateDate".')); + $this->serviceName = $input['ServiceName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceName".')); + $this->serviceUserName = $input['ServiceUserName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceUserName".')); + $this->servicePassword = $input['ServicePassword'] ?? $this->throwException(new InvalidArgument('Missing required field "ServicePassword".')); + $this->serviceSpecificCredentialId = $input['ServiceSpecificCredentialId'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceSpecificCredentialId".')); + $this->userName = $input['UserName'] ?? $this->throwException(new InvalidArgument('Missing required field "UserName".')); + $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".')); } /** @@ -124,4 +125,12 @@ public function getUserName(): string { return $this->userName; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iam/src/ValueObject/ServiceSpecificCredentialMetadata.php b/src/Service/Iam/src/ValueObject/ServiceSpecificCredentialMetadata.php index c2a603c5c..c001b3400 100644 --- a/src/Service/Iam/src/ValueObject/ServiceSpecificCredentialMetadata.php +++ b/src/Service/Iam/src/ValueObject/ServiceSpecificCredentialMetadata.php @@ -2,6 +2,7 @@ namespace AsyncAws\Iam\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Iam\Enum\StatusType; /** @@ -54,12 +55,12 @@ final class ServiceSpecificCredentialMetadata */ public function __construct(array $input) { - $this->userName = $input['UserName'] ?? null; - $this->status = $input['Status'] ?? null; - $this->serviceUserName = $input['ServiceUserName'] ?? null; - $this->createDate = $input['CreateDate'] ?? null; - $this->serviceSpecificCredentialId = $input['ServiceSpecificCredentialId'] ?? null; - $this->serviceName = $input['ServiceName'] ?? null; + $this->userName = $input['UserName'] ?? $this->throwException(new InvalidArgument('Missing required field "UserName".')); + $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".')); + $this->serviceUserName = $input['ServiceUserName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceUserName".')); + $this->createDate = $input['CreateDate'] ?? $this->throwException(new InvalidArgument('Missing required field "CreateDate".')); + $this->serviceSpecificCredentialId = $input['ServiceSpecificCredentialId'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceSpecificCredentialId".')); + $this->serviceName = $input['ServiceName'] ?? $this->throwException(new InvalidArgument('Missing required field "ServiceName".')); } /** @@ -109,4 +110,12 @@ public function getUserName(): string { return $this->userName; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iam/src/ValueObject/Tag.php b/src/Service/Iam/src/ValueObject/Tag.php index 0b4a6d1ad..9b4acd343 100644 --- a/src/Service/Iam/src/ValueObject/Tag.php +++ b/src/Service/Iam/src/ValueObject/Tag.php @@ -37,8 +37,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -68,15 +68,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iam/src/ValueObject/User.php b/src/Service/Iam/src/ValueObject/User.php index 948025065..b0deaa705 100644 --- a/src/Service/Iam/src/ValueObject/User.php +++ b/src/Service/Iam/src/ValueObject/User.php @@ -2,6 +2,8 @@ namespace AsyncAws\Iam\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains information about an IAM user entity. * @@ -100,11 +102,11 @@ final class User */ public function __construct(array $input) { - $this->path = $input['Path'] ?? null; - $this->userName = $input['UserName'] ?? null; - $this->userId = $input['UserId'] ?? null; - $this->arn = $input['Arn'] ?? null; - $this->createDate = $input['CreateDate'] ?? null; + $this->path = $input['Path'] ?? $this->throwException(new InvalidArgument('Missing required field "Path".')); + $this->userName = $input['UserName'] ?? $this->throwException(new InvalidArgument('Missing required field "UserName".')); + $this->userId = $input['UserId'] ?? $this->throwException(new InvalidArgument('Missing required field "UserId".')); + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); + $this->createDate = $input['CreateDate'] ?? $this->throwException(new InvalidArgument('Missing required field "CreateDate".')); $this->passwordLastUsed = $input['PasswordLastUsed'] ?? null; $this->permissionsBoundary = isset($input['PermissionsBoundary']) ? AttachedPermissionsBoundary::create($input['PermissionsBoundary']) : null; $this->tags = isset($input['Tags']) ? array_map([Tag::class, 'create'], $input['Tags']) : null; @@ -169,4 +171,12 @@ public function getUserName(): string { return $this->userName; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Iot/src/ValueObject/Tag.php b/src/Service/Iot/src/ValueObject/Tag.php index 7a784f8b5..cbfd3ec43 100644 --- a/src/Service/Iot/src/ValueObject/Tag.php +++ b/src/Service/Iot/src/ValueObject/Tag.php @@ -27,7 +27,7 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); $this->value = $input['Value'] ?? null; } @@ -58,9 +58,7 @@ public function getValue(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; if (null !== $v = $this->value) { $payload['Value'] = $v; @@ -68,4 +66,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/ChildShard.php b/src/Service/Kinesis/src/ValueObject/ChildShard.php index 29ccbee8b..65553a5be 100644 --- a/src/Service/Kinesis/src/ValueObject/ChildShard.php +++ b/src/Service/Kinesis/src/ValueObject/ChildShard.php @@ -2,6 +2,8 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Output parameter of the GetRecords API. The existing child shard of the current shard. */ @@ -28,9 +30,9 @@ final class ChildShard */ public function __construct(array $input) { - $this->shardId = $input['ShardId'] ?? null; - $this->parentShards = $input['ParentShards'] ?? null; - $this->hashKeyRange = isset($input['HashKeyRange']) ? HashKeyRange::create($input['HashKeyRange']) : null; + $this->shardId = $input['ShardId'] ?? $this->throwException(new InvalidArgument('Missing required field "ShardId".')); + $this->parentShards = $input['ParentShards'] ?? $this->throwException(new InvalidArgument('Missing required field "ParentShards".')); + $this->hashKeyRange = isset($input['HashKeyRange']) ? HashKeyRange::create($input['HashKeyRange']) : $this->throwException(new InvalidArgument('Missing required field "HashKeyRange".')); } /** @@ -55,11 +57,19 @@ public function getHashKeyRange(): HashKeyRange */ public function getParentShards(): array { - return $this->parentShards ?? []; + return $this->parentShards; } public function getShardId(): string { return $this->shardId; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/Consumer.php b/src/Service/Kinesis/src/ValueObject/Consumer.php index fe268d24f..bcafb1b6e 100644 --- a/src/Service/Kinesis/src/ValueObject/Consumer.php +++ b/src/Service/Kinesis/src/ValueObject/Consumer.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\ConsumerStatus; /** @@ -42,10 +43,10 @@ final class Consumer */ public function __construct(array $input) { - $this->consumerName = $input['ConsumerName'] ?? null; - $this->consumerArn = $input['ConsumerARN'] ?? null; - $this->consumerStatus = $input['ConsumerStatus'] ?? null; - $this->consumerCreationTimestamp = $input['ConsumerCreationTimestamp'] ?? null; + $this->consumerName = $input['ConsumerName'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerName".')); + $this->consumerArn = $input['ConsumerARN'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerARN".')); + $this->consumerStatus = $input['ConsumerStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerStatus".')); + $this->consumerCreationTimestamp = $input['ConsumerCreationTimestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerCreationTimestamp".')); } /** @@ -83,4 +84,12 @@ public function getConsumerStatus(): string { return $this->consumerStatus; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/ConsumerDescription.php b/src/Service/Kinesis/src/ValueObject/ConsumerDescription.php index 44b97bbc7..0158ffc2d 100644 --- a/src/Service/Kinesis/src/ValueObject/ConsumerDescription.php +++ b/src/Service/Kinesis/src/ValueObject/ConsumerDescription.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\ConsumerStatus; /** @@ -48,11 +49,11 @@ final class ConsumerDescription */ public function __construct(array $input) { - $this->consumerName = $input['ConsumerName'] ?? null; - $this->consumerArn = $input['ConsumerARN'] ?? null; - $this->consumerStatus = $input['ConsumerStatus'] ?? null; - $this->consumerCreationTimestamp = $input['ConsumerCreationTimestamp'] ?? null; - $this->streamArn = $input['StreamARN'] ?? null; + $this->consumerName = $input['ConsumerName'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerName".')); + $this->consumerArn = $input['ConsumerARN'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerARN".')); + $this->consumerStatus = $input['ConsumerStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerStatus".')); + $this->consumerCreationTimestamp = $input['ConsumerCreationTimestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "ConsumerCreationTimestamp".')); + $this->streamArn = $input['StreamARN'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamARN".')); } /** @@ -96,4 +97,12 @@ public function getStreamArn(): string { return $this->streamArn; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/HashKeyRange.php b/src/Service/Kinesis/src/ValueObject/HashKeyRange.php index 4b9ba383a..aa9a10da2 100644 --- a/src/Service/Kinesis/src/ValueObject/HashKeyRange.php +++ b/src/Service/Kinesis/src/ValueObject/HashKeyRange.php @@ -2,6 +2,8 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The range of possible hash key values for the shard, which is a set of ordered contiguous positive integers. */ @@ -25,8 +27,8 @@ final class HashKeyRange */ public function __construct(array $input) { - $this->startingHashKey = $input['StartingHashKey'] ?? null; - $this->endingHashKey = $input['EndingHashKey'] ?? null; + $this->startingHashKey = $input['StartingHashKey'] ?? $this->throwException(new InvalidArgument('Missing required field "StartingHashKey".')); + $this->endingHashKey = $input['EndingHashKey'] ?? $this->throwException(new InvalidArgument('Missing required field "EndingHashKey".')); } /** @@ -49,4 +51,12 @@ public function getStartingHashKey(): string { return $this->startingHashKey; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/PutRecordsRequestEntry.php b/src/Service/Kinesis/src/ValueObject/PutRecordsRequestEntry.php index d4f4a1d44..102082265 100644 --- a/src/Service/Kinesis/src/ValueObject/PutRecordsRequestEntry.php +++ b/src/Service/Kinesis/src/ValueObject/PutRecordsRequestEntry.php @@ -40,9 +40,9 @@ final class PutRecordsRequestEntry */ public function __construct(array $input) { - $this->data = $input['Data'] ?? null; + $this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".')); $this->explicitHashKey = $input['ExplicitHashKey'] ?? null; - $this->partitionKey = $input['PartitionKey'] ?? null; + $this->partitionKey = $input['PartitionKey'] ?? $this->throwException(new InvalidArgument('Missing required field "PartitionKey".')); } /** @@ -78,18 +78,22 @@ public function getPartitionKey(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->data) { - throw new InvalidArgument(sprintf('Missing parameter "Data" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->data; $payload['Data'] = base64_encode($v); if (null !== $v = $this->explicitHashKey) { $payload['ExplicitHashKey'] = $v; } - if (null === $v = $this->partitionKey) { - throw new InvalidArgument(sprintf('Missing parameter "PartitionKey" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->partitionKey; $payload['PartitionKey'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/Record.php b/src/Service/Kinesis/src/ValueObject/Record.php index 62616598e..6a729cbf4 100644 --- a/src/Service/Kinesis/src/ValueObject/Record.php +++ b/src/Service/Kinesis/src/ValueObject/Record.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\EncryptionType; /** @@ -52,10 +53,10 @@ final class Record */ public function __construct(array $input) { - $this->sequenceNumber = $input['SequenceNumber'] ?? null; + $this->sequenceNumber = $input['SequenceNumber'] ?? $this->throwException(new InvalidArgument('Missing required field "SequenceNumber".')); $this->approximateArrivalTimestamp = $input['ApproximateArrivalTimestamp'] ?? null; - $this->data = $input['Data'] ?? null; - $this->partitionKey = $input['PartitionKey'] ?? null; + $this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".')); + $this->partitionKey = $input['PartitionKey'] ?? $this->throwException(new InvalidArgument('Missing required field "PartitionKey".')); $this->encryptionType = $input['EncryptionType'] ?? null; } @@ -100,4 +101,12 @@ public function getSequenceNumber(): string { return $this->sequenceNumber; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/SequenceNumberRange.php b/src/Service/Kinesis/src/ValueObject/SequenceNumberRange.php index ae2f5b16a..52a7c69a7 100644 --- a/src/Service/Kinesis/src/ValueObject/SequenceNumberRange.php +++ b/src/Service/Kinesis/src/ValueObject/SequenceNumberRange.php @@ -2,6 +2,8 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The range of possible sequence numbers for the shard. */ @@ -25,7 +27,7 @@ final class SequenceNumberRange */ public function __construct(array $input) { - $this->startingSequenceNumber = $input['StartingSequenceNumber'] ?? null; + $this->startingSequenceNumber = $input['StartingSequenceNumber'] ?? $this->throwException(new InvalidArgument('Missing required field "StartingSequenceNumber".')); $this->endingSequenceNumber = $input['EndingSequenceNumber'] ?? null; } @@ -49,4 +51,12 @@ public function getStartingSequenceNumber(): string { return $this->startingSequenceNumber; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/Shard.php b/src/Service/Kinesis/src/ValueObject/Shard.php index 559e98a8a..22e2a378b 100644 --- a/src/Service/Kinesis/src/ValueObject/Shard.php +++ b/src/Service/Kinesis/src/ValueObject/Shard.php @@ -2,6 +2,8 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * A uniquely identified group of data records in a Kinesis data stream. */ @@ -43,11 +45,11 @@ final class Shard */ public function __construct(array $input) { - $this->shardId = $input['ShardId'] ?? null; + $this->shardId = $input['ShardId'] ?? $this->throwException(new InvalidArgument('Missing required field "ShardId".')); $this->parentShardId = $input['ParentShardId'] ?? null; $this->adjacentParentShardId = $input['AdjacentParentShardId'] ?? null; - $this->hashKeyRange = isset($input['HashKeyRange']) ? HashKeyRange::create($input['HashKeyRange']) : null; - $this->sequenceNumberRange = isset($input['SequenceNumberRange']) ? SequenceNumberRange::create($input['SequenceNumberRange']) : null; + $this->hashKeyRange = isset($input['HashKeyRange']) ? HashKeyRange::create($input['HashKeyRange']) : $this->throwException(new InvalidArgument('Missing required field "HashKeyRange".')); + $this->sequenceNumberRange = isset($input['SequenceNumberRange']) ? SequenceNumberRange::create($input['SequenceNumberRange']) : $this->throwException(new InvalidArgument('Missing required field "SequenceNumberRange".')); } /** @@ -88,4 +90,12 @@ public function getShardId(): string { return $this->shardId; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/ShardFilter.php b/src/Service/Kinesis/src/ValueObject/ShardFilter.php index 758e78b5e..23017d50d 100644 --- a/src/Service/Kinesis/src/ValueObject/ShardFilter.php +++ b/src/Service/Kinesis/src/ValueObject/ShardFilter.php @@ -51,7 +51,7 @@ final class ShardFilter */ public function __construct(array $input) { - $this->type = $input['Type'] ?? null; + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); $this->shardId = $input['ShardId'] ?? null; $this->timestamp = $input['Timestamp'] ?? null; } @@ -92,9 +92,7 @@ public function getType(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "Type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!ShardFilterType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "Type" for "%s". The value "%s" is not a valid "ShardFilterType".', __CLASS__, $v)); } @@ -108,4 +106,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/StreamDescription.php b/src/Service/Kinesis/src/ValueObject/StreamDescription.php index 6563a1db1..4b5635238 100644 --- a/src/Service/Kinesis/src/ValueObject/StreamDescription.php +++ b/src/Service/Kinesis/src/ValueObject/StreamDescription.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\EncryptionType; use AsyncAws\Kinesis\Enum\StreamStatus; @@ -104,15 +105,15 @@ final class StreamDescription */ public function __construct(array $input) { - $this->streamName = $input['StreamName'] ?? null; - $this->streamArn = $input['StreamARN'] ?? null; - $this->streamStatus = $input['StreamStatus'] ?? null; + $this->streamName = $input['StreamName'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamName".')); + $this->streamArn = $input['StreamARN'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamARN".')); + $this->streamStatus = $input['StreamStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamStatus".')); $this->streamModeDetails = isset($input['StreamModeDetails']) ? StreamModeDetails::create($input['StreamModeDetails']) : null; - $this->shards = isset($input['Shards']) ? array_map([Shard::class, 'create'], $input['Shards']) : null; - $this->hasMoreShards = $input['HasMoreShards'] ?? null; - $this->retentionPeriodHours = $input['RetentionPeriodHours'] ?? null; - $this->streamCreationTimestamp = $input['StreamCreationTimestamp'] ?? null; - $this->enhancedMonitoring = isset($input['EnhancedMonitoring']) ? array_map([EnhancedMetrics::class, 'create'], $input['EnhancedMonitoring']) : null; + $this->shards = isset($input['Shards']) ? array_map([Shard::class, 'create'], $input['Shards']) : $this->throwException(new InvalidArgument('Missing required field "Shards".')); + $this->hasMoreShards = $input['HasMoreShards'] ?? $this->throwException(new InvalidArgument('Missing required field "HasMoreShards".')); + $this->retentionPeriodHours = $input['RetentionPeriodHours'] ?? $this->throwException(new InvalidArgument('Missing required field "RetentionPeriodHours".')); + $this->streamCreationTimestamp = $input['StreamCreationTimestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamCreationTimestamp".')); + $this->enhancedMonitoring = isset($input['EnhancedMonitoring']) ? array_map([EnhancedMetrics::class, 'create'], $input['EnhancedMonitoring']) : $this->throwException(new InvalidArgument('Missing required field "EnhancedMonitoring".')); $this->encryptionType = $input['EncryptionType'] ?? null; $this->keyId = $input['KeyId'] ?? null; } @@ -150,7 +151,7 @@ public function getEncryptionType(): ?string */ public function getEnhancedMonitoring(): array { - return $this->enhancedMonitoring ?? []; + return $this->enhancedMonitoring; } public function getHasMoreShards(): bool @@ -173,7 +174,7 @@ public function getRetentionPeriodHours(): int */ public function getShards(): array { - return $this->shards ?? []; + return $this->shards; } public function getStreamArn(): string @@ -203,4 +204,12 @@ public function getStreamStatus(): string { return $this->streamStatus; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/StreamDescriptionSummary.php b/src/Service/Kinesis/src/ValueObject/StreamDescriptionSummary.php index 661e18367..6d29315d4 100644 --- a/src/Service/Kinesis/src/ValueObject/StreamDescriptionSummary.php +++ b/src/Service/Kinesis/src/ValueObject/StreamDescriptionSummary.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\EncryptionType; use AsyncAws\Kinesis\Enum\StreamStatus; @@ -103,16 +104,16 @@ final class StreamDescriptionSummary */ public function __construct(array $input) { - $this->streamName = $input['StreamName'] ?? null; - $this->streamArn = $input['StreamARN'] ?? null; - $this->streamStatus = $input['StreamStatus'] ?? null; + $this->streamName = $input['StreamName'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamName".')); + $this->streamArn = $input['StreamARN'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamARN".')); + $this->streamStatus = $input['StreamStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamStatus".')); $this->streamModeDetails = isset($input['StreamModeDetails']) ? StreamModeDetails::create($input['StreamModeDetails']) : null; - $this->retentionPeriodHours = $input['RetentionPeriodHours'] ?? null; - $this->streamCreationTimestamp = $input['StreamCreationTimestamp'] ?? null; - $this->enhancedMonitoring = isset($input['EnhancedMonitoring']) ? array_map([EnhancedMetrics::class, 'create'], $input['EnhancedMonitoring']) : null; + $this->retentionPeriodHours = $input['RetentionPeriodHours'] ?? $this->throwException(new InvalidArgument('Missing required field "RetentionPeriodHours".')); + $this->streamCreationTimestamp = $input['StreamCreationTimestamp'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamCreationTimestamp".')); + $this->enhancedMonitoring = isset($input['EnhancedMonitoring']) ? array_map([EnhancedMetrics::class, 'create'], $input['EnhancedMonitoring']) : $this->throwException(new InvalidArgument('Missing required field "EnhancedMonitoring".')); $this->encryptionType = $input['EncryptionType'] ?? null; $this->keyId = $input['KeyId'] ?? null; - $this->openShardCount = $input['OpenShardCount'] ?? null; + $this->openShardCount = $input['OpenShardCount'] ?? $this->throwException(new InvalidArgument('Missing required field "OpenShardCount".')); $this->consumerCount = $input['ConsumerCount'] ?? null; } @@ -154,7 +155,7 @@ public function getEncryptionType(): ?string */ public function getEnhancedMonitoring(): array { - return $this->enhancedMonitoring ?? []; + return $this->enhancedMonitoring; } public function getKeyId(): ?string @@ -199,4 +200,12 @@ public function getStreamStatus(): string { return $this->streamStatus; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/StreamModeDetails.php b/src/Service/Kinesis/src/ValueObject/StreamModeDetails.php index fda4763e8..c389c0a7d 100644 --- a/src/Service/Kinesis/src/ValueObject/StreamModeDetails.php +++ b/src/Service/Kinesis/src/ValueObject/StreamModeDetails.php @@ -24,7 +24,7 @@ final class StreamModeDetails */ public function __construct(array $input) { - $this->streamMode = $input['StreamMode'] ?? null; + $this->streamMode = $input['StreamMode'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamMode".')); } /** @@ -51,9 +51,7 @@ public function getStreamMode(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->streamMode) { - throw new InvalidArgument(sprintf('Missing parameter "StreamMode" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->streamMode; if (!StreamMode::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "StreamMode" for "%s". The value "%s" is not a valid "StreamMode".', __CLASS__, $v)); } @@ -61,4 +59,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/StreamSummary.php b/src/Service/Kinesis/src/ValueObject/StreamSummary.php index 184df1b36..fbc9e3436 100644 --- a/src/Service/Kinesis/src/ValueObject/StreamSummary.php +++ b/src/Service/Kinesis/src/ValueObject/StreamSummary.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kinesis\Enum\StreamStatus; /** @@ -42,9 +43,9 @@ final class StreamSummary */ public function __construct(array $input) { - $this->streamName = $input['StreamName'] ?? null; - $this->streamArn = $input['StreamARN'] ?? null; - $this->streamStatus = $input['StreamStatus'] ?? null; + $this->streamName = $input['StreamName'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamName".')); + $this->streamArn = $input['StreamARN'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamARN".')); + $this->streamStatus = $input['StreamStatus'] ?? $this->throwException(new InvalidArgument('Missing required field "StreamStatus".')); $this->streamModeDetails = isset($input['StreamModeDetails']) ? StreamModeDetails::create($input['StreamModeDetails']) : null; $this->streamCreationTimestamp = $input['StreamCreationTimestamp'] ?? null; } @@ -90,4 +91,12 @@ public function getStreamStatus(): string { return $this->streamStatus; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kinesis/src/ValueObject/Tag.php b/src/Service/Kinesis/src/ValueObject/Tag.php index 12ef5739c..720854963 100644 --- a/src/Service/Kinesis/src/ValueObject/Tag.php +++ b/src/Service/Kinesis/src/ValueObject/Tag.php @@ -2,6 +2,8 @@ namespace AsyncAws\Kinesis\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Metadata assigned to the stream, consisting of a key-value pair. */ @@ -27,7 +29,7 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); $this->value = $input['Value'] ?? null; } @@ -51,4 +53,12 @@ public function getValue(): ?string { return $this->value; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kms/src/ValueObject/KeyMetadata.php b/src/Service/Kms/src/ValueObject/KeyMetadata.php index 5498ba240..b1b05913e 100644 --- a/src/Service/Kms/src/ValueObject/KeyMetadata.php +++ b/src/Service/Kms/src/ValueObject/KeyMetadata.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kms\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Kms\Enum\CustomerMasterKeySpec; use AsyncAws\Kms\Enum\EncryptionAlgorithmSpec; use AsyncAws\Kms\Enum\ExpirationModelType; @@ -241,7 +242,7 @@ final class KeyMetadata public function __construct(array $input) { $this->awsAccountId = $input['AWSAccountId'] ?? null; - $this->keyId = $input['KeyId'] ?? null; + $this->keyId = $input['KeyId'] ?? $this->throwException(new InvalidArgument('Missing required field "KeyId".')); $this->arn = $input['Arn'] ?? null; $this->creationDate = $input['CreationDate'] ?? null; $this->enabled = $input['Enabled'] ?? null; @@ -452,4 +453,12 @@ public function getXksKeyConfiguration(): ?XksKeyConfigurationType { return $this->xksKeyConfiguration; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Kms/src/ValueObject/Tag.php b/src/Service/Kms/src/ValueObject/Tag.php index 24db158f2..372b613d0 100644 --- a/src/Service/Kms/src/ValueObject/Tag.php +++ b/src/Service/Kms/src/ValueObject/Tag.php @@ -36,8 +36,8 @@ final class Tag */ public function __construct(array $input) { - $this->tagKey = $input['TagKey'] ?? null; - $this->tagValue = $input['TagValue'] ?? null; + $this->tagKey = $input['TagKey'] ?? $this->throwException(new InvalidArgument('Missing required field "TagKey".')); + $this->tagValue = $input['TagValue'] ?? $this->throwException(new InvalidArgument('Missing required field "TagValue".')); } /** @@ -67,15 +67,19 @@ public function getTagValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->tagKey) { - throw new InvalidArgument(sprintf('Missing parameter "TagKey" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tagKey; $payload['TagKey'] = $v; - if (null === $v = $this->tagValue) { - throw new InvalidArgument(sprintf('Missing parameter "TagValue" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tagValue; $payload['TagValue'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Lambda/src/ValueObject/EphemeralStorage.php b/src/Service/Lambda/src/ValueObject/EphemeralStorage.php index ef6adf2ff..9fe9673d8 100644 --- a/src/Service/Lambda/src/ValueObject/EphemeralStorage.php +++ b/src/Service/Lambda/src/ValueObject/EphemeralStorage.php @@ -2,6 +2,8 @@ namespace AsyncAws\Lambda\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The size of the function's `/tmp` directory in MB. The default value is 512, but it can be any whole number between * 512 and 10,240 MB. @@ -20,7 +22,7 @@ final class EphemeralStorage */ public function __construct(array $input) { - $this->size = $input['Size'] ?? null; + $this->size = $input['Size'] ?? $this->throwException(new InvalidArgument('Missing required field "Size".')); } /** @@ -37,4 +39,12 @@ public function getSize(): int { return $this->size; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Lambda/src/ValueObject/FileSystemConfig.php b/src/Service/Lambda/src/ValueObject/FileSystemConfig.php index e0c12f3db..f5e6d48cd 100644 --- a/src/Service/Lambda/src/ValueObject/FileSystemConfig.php +++ b/src/Service/Lambda/src/ValueObject/FileSystemConfig.php @@ -2,6 +2,8 @@ namespace AsyncAws\Lambda\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Details about the connection between a Lambda function and an Amazon EFS file system [^1]. * @@ -27,8 +29,8 @@ final class FileSystemConfig */ public function __construct(array $input) { - $this->arn = $input['Arn'] ?? null; - $this->localMountPath = $input['LocalMountPath'] ?? null; + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); + $this->localMountPath = $input['LocalMountPath'] ?? $this->throwException(new InvalidArgument('Missing required field "LocalMountPath".')); } /** @@ -51,4 +53,12 @@ public function getLocalMountPath(): string { return $this->localMountPath; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/MediaConvert/src/ValueObject/AccelerationSettings.php b/src/Service/MediaConvert/src/ValueObject/AccelerationSettings.php index 53c0ab7d6..c710bfd82 100644 --- a/src/Service/MediaConvert/src/ValueObject/AccelerationSettings.php +++ b/src/Service/MediaConvert/src/ValueObject/AccelerationSettings.php @@ -22,7 +22,7 @@ final class AccelerationSettings */ public function __construct(array $input) { - $this->mode = $input['Mode'] ?? null; + $this->mode = $input['Mode'] ?? $this->throwException(new InvalidArgument('Missing required field "Mode".')); } /** @@ -49,9 +49,7 @@ public function getMode(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->mode) { - throw new InvalidArgument(sprintf('Missing parameter "Mode" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->mode; if (!AccelerationMode::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "mode" for "%s". The value "%s" is not a valid "AccelerationMode".', __CLASS__, $v)); } @@ -59,4 +57,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/MediaConvert/src/ValueObject/Job.php b/src/Service/MediaConvert/src/ValueObject/Job.php index f8f86b6ab..0c3b435b0 100644 --- a/src/Service/MediaConvert/src/ValueObject/Job.php +++ b/src/Service/MediaConvert/src/ValueObject/Job.php @@ -2,6 +2,7 @@ namespace AsyncAws\MediaConvert\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\MediaConvert\Enum\AccelerationStatus; use AsyncAws\MediaConvert\Enum\BillingTagsSource; use AsyncAws\MediaConvert\Enum\JobPhase; @@ -226,8 +227,8 @@ public function __construct(array $input) $this->queue = $input['Queue'] ?? null; $this->queueTransitions = isset($input['QueueTransitions']) ? array_map([QueueTransition::class, 'create'], $input['QueueTransitions']) : null; $this->retryCount = $input['RetryCount'] ?? null; - $this->role = $input['Role'] ?? null; - $this->settings = isset($input['Settings']) ? JobSettings::create($input['Settings']) : null; + $this->role = $input['Role'] ?? $this->throwException(new InvalidArgument('Missing required field "Role".')); + $this->settings = isset($input['Settings']) ? JobSettings::create($input['Settings']) : $this->throwException(new InvalidArgument('Missing required field "Settings".')); $this->simulateReservedQueue = $input['SimulateReservedQueue'] ?? null; $this->status = $input['Status'] ?? null; $this->statusUpdateInterval = $input['StatusUpdateInterval'] ?? null; @@ -439,4 +440,12 @@ public function getWarnings(): array { return $this->warnings ?? []; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/MediaConvert/src/ValueObject/WarningGroup.php b/src/Service/MediaConvert/src/ValueObject/WarningGroup.php index 1067fddb0..3f273f9b5 100644 --- a/src/Service/MediaConvert/src/ValueObject/WarningGroup.php +++ b/src/Service/MediaConvert/src/ValueObject/WarningGroup.php @@ -2,6 +2,8 @@ namespace AsyncAws\MediaConvert\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains any warning codes and their count for the job. */ @@ -26,8 +28,8 @@ final class WarningGroup */ public function __construct(array $input) { - $this->code = $input['Code'] ?? null; - $this->count = $input['Count'] ?? null; + $this->code = $input['Code'] ?? $this->throwException(new InvalidArgument('Missing required field "Code".')); + $this->count = $input['Count'] ?? $this->throwException(new InvalidArgument('Missing required field "Count".')); } /** @@ -50,4 +52,12 @@ public function getCount(): int { return $this->count; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Rekognition/src/ValueObject/HumanLoopConfig.php b/src/Service/Rekognition/src/ValueObject/HumanLoopConfig.php index 6a869b70c..80db499b2 100644 --- a/src/Service/Rekognition/src/ValueObject/HumanLoopConfig.php +++ b/src/Service/Rekognition/src/ValueObject/HumanLoopConfig.php @@ -37,8 +37,8 @@ final class HumanLoopConfig */ public function __construct(array $input) { - $this->humanLoopName = $input['HumanLoopName'] ?? null; - $this->flowDefinitionArn = $input['FlowDefinitionArn'] ?? null; + $this->humanLoopName = $input['HumanLoopName'] ?? $this->throwException(new InvalidArgument('Missing required field "HumanLoopName".')); + $this->flowDefinitionArn = $input['FlowDefinitionArn'] ?? $this->throwException(new InvalidArgument('Missing required field "FlowDefinitionArn".')); $this->dataAttributes = isset($input['DataAttributes']) ? HumanLoopDataAttributes::create($input['DataAttributes']) : null; } @@ -75,13 +75,9 @@ public function getHumanLoopName(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->humanLoopName) { - throw new InvalidArgument(sprintf('Missing parameter "HumanLoopName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->humanLoopName; $payload['HumanLoopName'] = $v; - if (null === $v = $this->flowDefinitionArn) { - throw new InvalidArgument(sprintf('Missing parameter "FlowDefinitionArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->flowDefinitionArn; $payload['FlowDefinitionArn'] = $v; if (null !== $v = $this->dataAttributes) { $payload['DataAttributes'] = $v->requestBody(); @@ -89,4 +85,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/AliasTarget.php b/src/Service/Route53/src/ValueObject/AliasTarget.php index 339925bc5..0c74531f7 100644 --- a/src/Service/Route53/src/ValueObject/AliasTarget.php +++ b/src/Service/Route53/src/ValueObject/AliasTarget.php @@ -282,9 +282,9 @@ final class AliasTarget */ public function __construct(array $input) { - $this->hostedZoneId = $input['HostedZoneId'] ?? null; - $this->dnsName = $input['DNSName'] ?? null; - $this->evaluateTargetHealth = $input['EvaluateTargetHealth'] ?? null; + $this->hostedZoneId = $input['HostedZoneId'] ?? $this->throwException(new InvalidArgument('Missing required field "HostedZoneId".')); + $this->dnsName = $input['DNSName'] ?? $this->throwException(new InvalidArgument('Missing required field "DNSName".')); + $this->evaluateTargetHealth = $input['EvaluateTargetHealth'] ?? $this->throwException(new InvalidArgument('Missing required field "EvaluateTargetHealth".')); } /** @@ -319,17 +319,19 @@ public function getHostedZoneId(): string */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->hostedZoneId) { - throw new InvalidArgument(sprintf('Missing parameter "HostedZoneId" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->hostedZoneId; $node->appendChild($document->createElement('HostedZoneId', $v)); - if (null === $v = $this->dnsName) { - throw new InvalidArgument(sprintf('Missing parameter "DNSName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->dnsName; $node->appendChild($document->createElement('DNSName', $v)); - if (null === $v = $this->evaluateTargetHealth) { - throw new InvalidArgument(sprintf('Missing parameter "EvaluateTargetHealth" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->evaluateTargetHealth; $node->appendChild($document->createElement('EvaluateTargetHealth', $v ? 'true' : 'false')); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/Change.php b/src/Service/Route53/src/ValueObject/Change.php index e8ca22f3a..ac3214a7b 100644 --- a/src/Service/Route53/src/ValueObject/Change.php +++ b/src/Service/Route53/src/ValueObject/Change.php @@ -41,8 +41,8 @@ final class Change */ public function __construct(array $input) { - $this->action = $input['Action'] ?? null; - $this->resourceRecordSet = isset($input['ResourceRecordSet']) ? ResourceRecordSet::create($input['ResourceRecordSet']) : null; + $this->action = $input['Action'] ?? $this->throwException(new InvalidArgument('Missing required field "Action".')); + $this->resourceRecordSet = isset($input['ResourceRecordSet']) ? ResourceRecordSet::create($input['ResourceRecordSet']) : $this->throwException(new InvalidArgument('Missing required field "ResourceRecordSet".')); } /** @@ -74,19 +74,23 @@ public function getResourceRecordSet(): ResourceRecordSet */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->action) { - throw new InvalidArgument(sprintf('Missing parameter "Action" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->action; if (!ChangeAction::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "Action" for "%s". The value "%s" is not a valid "ChangeAction".', __CLASS__, $v)); } $node->appendChild($document->createElement('Action', $v)); - if (null === $v = $this->resourceRecordSet) { - throw new InvalidArgument(sprintf('Missing parameter "ResourceRecordSet" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->resourceRecordSet; $node->appendChild($child = $document->createElement('ResourceRecordSet')); $v->requestBody($child, $document); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/ChangeBatch.php b/src/Service/Route53/src/ValueObject/ChangeBatch.php index a8981657d..0e2b7f9cd 100644 --- a/src/Service/Route53/src/ValueObject/ChangeBatch.php +++ b/src/Service/Route53/src/ValueObject/ChangeBatch.php @@ -28,7 +28,7 @@ final class ChangeBatch public function __construct(array $input) { $this->comment = $input['Comment'] ?? null; - $this->changes = isset($input['Changes']) ? array_map([Change::class, 'create'], $input['Changes']) : null; + $this->changes = isset($input['Changes']) ? array_map([Change::class, 'create'], $input['Changes']) : $this->throwException(new InvalidArgument('Missing required field "Changes".')); } /** @@ -47,7 +47,7 @@ public static function create($input): self */ public function getChanges(): array { - return $this->changes ?? []; + return $this->changes; } public function getComment(): ?string @@ -63,9 +63,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void if (null !== $v = $this->comment) { $node->appendChild($document->createElement('Comment', $v)); } - if (null === $v = $this->changes) { - throw new InvalidArgument(sprintf('Missing parameter "Changes" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->changes; $node->appendChild($nodeList = $document->createElement('Changes')); foreach ($v as $item) { @@ -74,4 +72,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $item->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/ChangeInfo.php b/src/Service/Route53/src/ValueObject/ChangeInfo.php index aaa94a198..ef60fb295 100644 --- a/src/Service/Route53/src/ValueObject/ChangeInfo.php +++ b/src/Service/Route53/src/ValueObject/ChangeInfo.php @@ -2,6 +2,7 @@ namespace AsyncAws\Route53\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\Route53\Enum\ChangeStatus; /** @@ -46,9 +47,9 @@ final class ChangeInfo */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->status = $input['Status'] ?? null; - $this->submittedAt = $input['SubmittedAt'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->status = $input['Status'] ?? $this->throwException(new InvalidArgument('Missing required field "Status".')); + $this->submittedAt = $input['SubmittedAt'] ?? $this->throwException(new InvalidArgument('Missing required field "SubmittedAt".')); $this->comment = $input['Comment'] ?? null; } @@ -87,4 +88,12 @@ public function getSubmittedAt(): \DateTimeImmutable { return $this->submittedAt; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/CidrRoutingConfig.php b/src/Service/Route53/src/ValueObject/CidrRoutingConfig.php index 918195cf7..8fc760f12 100644 --- a/src/Service/Route53/src/ValueObject/CidrRoutingConfig.php +++ b/src/Service/Route53/src/ValueObject/CidrRoutingConfig.php @@ -31,8 +31,8 @@ final class CidrRoutingConfig */ public function __construct(array $input) { - $this->collectionId = $input['CollectionId'] ?? null; - $this->locationName = $input['LocationName'] ?? null; + $this->collectionId = $input['CollectionId'] ?? $this->throwException(new InvalidArgument('Missing required field "CollectionId".')); + $this->locationName = $input['LocationName'] ?? $this->throwException(new InvalidArgument('Missing required field "LocationName".')); } /** @@ -61,13 +61,17 @@ public function getLocationName(): string */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->collectionId) { - throw new InvalidArgument(sprintf('Missing parameter "CollectionId" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->collectionId; $node->appendChild($document->createElement('CollectionId', $v)); - if (null === $v = $this->locationName) { - throw new InvalidArgument(sprintf('Missing parameter "LocationName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->locationName; $node->appendChild($document->createElement('LocationName', $v)); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/DelegationSet.php b/src/Service/Route53/src/ValueObject/DelegationSet.php index 8a9aeb576..2735da282 100644 --- a/src/Service/Route53/src/ValueObject/DelegationSet.php +++ b/src/Service/Route53/src/ValueObject/DelegationSet.php @@ -2,6 +2,8 @@ namespace AsyncAws\Route53\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * A complex type that lists the name servers in a delegation set, as well as the `CallerReference` and the `ID` for the * delegation set. @@ -35,7 +37,7 @@ public function __construct(array $input) { $this->id = $input['Id'] ?? null; $this->callerReference = $input['CallerReference'] ?? null; - $this->nameServers = $input['NameServers'] ?? null; + $this->nameServers = $input['NameServers'] ?? $this->throwException(new InvalidArgument('Missing required field "NameServers".')); } /** @@ -65,6 +67,14 @@ public function getId(): ?string */ public function getNameServers(): array { - return $this->nameServers ?? []; + return $this->nameServers; + } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; } } diff --git a/src/Service/Route53/src/ValueObject/HostedZone.php b/src/Service/Route53/src/ValueObject/HostedZone.php index e8c651996..a33a46dfd 100644 --- a/src/Service/Route53/src/ValueObject/HostedZone.php +++ b/src/Service/Route53/src/ValueObject/HostedZone.php @@ -2,6 +2,8 @@ namespace AsyncAws\Route53\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * A complex type that contains general information about the hosted zone. */ @@ -56,9 +58,9 @@ final class HostedZone */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->name = $input['Name'] ?? null; - $this->callerReference = $input['CallerReference'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->callerReference = $input['CallerReference'] ?? $this->throwException(new InvalidArgument('Missing required field "CallerReference".')); $this->config = isset($input['Config']) ? HostedZoneConfig::create($input['Config']) : null; $this->resourceRecordSetCount = $input['ResourceRecordSetCount'] ?? null; $this->linkedService = isset($input['LinkedService']) ? LinkedService::create($input['LinkedService']) : null; @@ -108,4 +110,12 @@ public function getResourceRecordSetCount(): ?int { return $this->resourceRecordSetCount; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/ResourceRecord.php b/src/Service/Route53/src/ValueObject/ResourceRecord.php index f7160203c..dfc33f509 100644 --- a/src/Service/Route53/src/ValueObject/ResourceRecord.php +++ b/src/Service/Route53/src/ValueObject/ResourceRecord.php @@ -31,7 +31,7 @@ final class ResourceRecord */ public function __construct(array $input) { - $this->value = $input['Value'] ?? null; + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -54,9 +54,15 @@ public function getValue(): string */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $node->appendChild($document->createElement('Value', $v)); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Route53/src/ValueObject/ResourceRecordSet.php b/src/Service/Route53/src/ValueObject/ResourceRecordSet.php index e9e51158a..b25d29ed5 100644 --- a/src/Service/Route53/src/ValueObject/ResourceRecordSet.php +++ b/src/Service/Route53/src/ValueObject/ResourceRecordSet.php @@ -400,8 +400,8 @@ final class ResourceRecordSet */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->type = $input['Type'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); $this->setIdentifier = $input['SetIdentifier'] ?? null; $this->weight = $input['Weight'] ?? null; $this->region = $input['Region'] ?? null; @@ -526,13 +526,9 @@ public function getWeight(): ?int */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $node->appendChild($document->createElement('Name', $v)); - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "Type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!RRType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "Type" for "%s". The value "%s" is not a valid "RRType".', __CLASS__, $v)); } @@ -591,4 +587,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $v->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/CORSConfiguration.php b/src/Service/S3/src/ValueObject/CORSConfiguration.php index 78a8bd006..39a8c57cc 100644 --- a/src/Service/S3/src/ValueObject/CORSConfiguration.php +++ b/src/Service/S3/src/ValueObject/CORSConfiguration.php @@ -25,7 +25,7 @@ final class CORSConfiguration */ public function __construct(array $input) { - $this->corsRules = isset($input['CORSRules']) ? array_map([CORSRule::class, 'create'], $input['CORSRules']) : null; + $this->corsRules = isset($input['CORSRules']) ? array_map([CORSRule::class, 'create'], $input['CORSRules']) : $this->throwException(new InvalidArgument('Missing required field "CORSRules".')); } /** @@ -43,7 +43,7 @@ public static function create($input): self */ public function getCorsRules(): array { - return $this->corsRules ?? []; + return $this->corsRules; } /** @@ -51,13 +51,19 @@ public function getCorsRules(): array */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->corsRules) { - throw new InvalidArgument(sprintf('Missing parameter "CORSRules" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->corsRules; foreach ($v as $item) { $node->appendChild($child = $document->createElement('CORSRule')); $item->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/CORSRule.php b/src/Service/S3/src/ValueObject/CORSRule.php index 7ba5f3c61..1e14a3f73 100644 --- a/src/Service/S3/src/ValueObject/CORSRule.php +++ b/src/Service/S3/src/ValueObject/CORSRule.php @@ -56,8 +56,8 @@ public function __construct(array $input) { $this->id = $input['ID'] ?? null; $this->allowedHeaders = $input['AllowedHeaders'] ?? null; - $this->allowedMethods = $input['AllowedMethods'] ?? null; - $this->allowedOrigins = $input['AllowedOrigins'] ?? null; + $this->allowedMethods = $input['AllowedMethods'] ?? $this->throwException(new InvalidArgument('Missing required field "AllowedMethods".')); + $this->allowedOrigins = $input['AllowedOrigins'] ?? $this->throwException(new InvalidArgument('Missing required field "AllowedOrigins".')); $this->exposeHeaders = $input['ExposeHeaders'] ?? null; $this->maxAgeSeconds = $input['MaxAgeSeconds'] ?? null; } @@ -90,7 +90,7 @@ public function getAllowedHeaders(): array */ public function getAllowedMethods(): array { - return $this->allowedMethods ?? []; + return $this->allowedMethods; } /** @@ -98,7 +98,7 @@ public function getAllowedMethods(): array */ public function getAllowedOrigins(): array { - return $this->allowedOrigins ?? []; + return $this->allowedOrigins; } /** @@ -132,16 +132,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $node->appendChild($document->createElement('AllowedHeader', $item)); } } - if (null === $v = $this->allowedMethods) { - throw new InvalidArgument(sprintf('Missing parameter "AllowedMethods" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->allowedMethods; foreach ($v as $item) { $node->appendChild($document->createElement('AllowedMethod', $item)); } - if (null === $v = $this->allowedOrigins) { - throw new InvalidArgument(sprintf('Missing parameter "AllowedOrigins" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->allowedOrigins; foreach ($v as $item) { $node->appendChild($document->createElement('AllowedOrigin', $item)); } @@ -155,4 +151,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $node->appendChild($document->createElement('MaxAgeSeconds', (string) $v)); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/Delete.php b/src/Service/S3/src/ValueObject/Delete.php index bf0f0b322..9808c3555 100644 --- a/src/Service/S3/src/ValueObject/Delete.php +++ b/src/Service/S3/src/ValueObject/Delete.php @@ -27,7 +27,7 @@ final class Delete */ public function __construct(array $input) { - $this->objects = isset($input['Objects']) ? array_map([ObjectIdentifier::class, 'create'], $input['Objects']) : null; + $this->objects = isset($input['Objects']) ? array_map([ObjectIdentifier::class, 'create'], $input['Objects']) : $this->throwException(new InvalidArgument('Missing required field "Objects".')); $this->quiet = $input['Quiet'] ?? null; } @@ -47,7 +47,7 @@ public static function create($input): self */ public function getObjects(): array { - return $this->objects ?? []; + return $this->objects; } public function getQuiet(): ?bool @@ -60,9 +60,7 @@ public function getQuiet(): ?bool */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->objects) { - throw new InvalidArgument(sprintf('Missing parameter "Objects" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->objects; foreach ($v as $item) { $node->appendChild($child = $document->createElement('Object')); @@ -73,4 +71,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $node->appendChild($document->createElement('Quiet', $v ? 'true' : 'false')); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/Grantee.php b/src/Service/S3/src/ValueObject/Grantee.php index ed79eec72..7d8e269ac 100644 --- a/src/Service/S3/src/ValueObject/Grantee.php +++ b/src/Service/S3/src/ValueObject/Grantee.php @@ -65,7 +65,7 @@ public function __construct(array $input) $this->displayName = $input['DisplayName'] ?? null; $this->emailAddress = $input['EmailAddress'] ?? null; $this->id = $input['ID'] ?? null; - $this->type = $input['Type'] ?? null; + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); $this->uri = $input['URI'] ?? null; } @@ -125,9 +125,7 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void if (null !== $v = $this->id) { $node->appendChild($document->createElement('ID', $v)); } - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "Type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!Type::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "xsi:type" for "%s". The value "%s" is not a valid "Type".', __CLASS__, $v)); } @@ -136,4 +134,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $node->appendChild($document->createElement('URI', $v)); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/LambdaFunctionConfiguration.php b/src/Service/S3/src/ValueObject/LambdaFunctionConfiguration.php index 94d616826..9f7a44345 100644 --- a/src/Service/S3/src/ValueObject/LambdaFunctionConfiguration.php +++ b/src/Service/S3/src/ValueObject/LambdaFunctionConfiguration.php @@ -38,8 +38,8 @@ final class LambdaFunctionConfiguration public function __construct(array $input) { $this->id = $input['Id'] ?? null; - $this->lambdaFunctionArn = $input['LambdaFunctionArn'] ?? null; - $this->events = $input['Events'] ?? null; + $this->lambdaFunctionArn = $input['LambdaFunctionArn'] ?? $this->throwException(new InvalidArgument('Missing required field "LambdaFunctionArn".')); + $this->events = $input['Events'] ?? $this->throwException(new InvalidArgument('Missing required field "Events".')); $this->filter = isset($input['Filter']) ? NotificationConfigurationFilter::create($input['Filter']) : null; } @@ -61,7 +61,7 @@ public static function create($input): self */ public function getEvents(): array { - return $this->events ?? []; + return $this->events; } public function getFilter(): ?NotificationConfigurationFilter @@ -87,13 +87,9 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void if (null !== $v = $this->id) { $node->appendChild($document->createElement('Id', $v)); } - if (null === $v = $this->lambdaFunctionArn) { - throw new InvalidArgument(sprintf('Missing parameter "LambdaFunctionArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->lambdaFunctionArn; $node->appendChild($document->createElement('CloudFunction', $v)); - if (null === $v = $this->events) { - throw new InvalidArgument(sprintf('Missing parameter "Events" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->events; foreach ($v as $item) { if (!Event::exists($item)) { throw new InvalidArgument(sprintf('Invalid parameter "Event" for "%s". The value "%s" is not a valid "Event".', __CLASS__, $item)); @@ -107,4 +103,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $v->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/ObjectIdentifier.php b/src/Service/S3/src/ValueObject/ObjectIdentifier.php index 7b5a90df4..4b7a150f1 100644 --- a/src/Service/S3/src/ValueObject/ObjectIdentifier.php +++ b/src/Service/S3/src/ValueObject/ObjectIdentifier.php @@ -32,7 +32,7 @@ final class ObjectIdentifier */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); $this->versionId = $input['VersionId'] ?? null; } @@ -62,12 +62,18 @@ public function getVersionId(): ?string */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $node->appendChild($document->createElement('Key', $v)); if (null !== $v = $this->versionId) { $node->appendChild($document->createElement('VersionId', $v)); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/QueueConfiguration.php b/src/Service/S3/src/ValueObject/QueueConfiguration.php index fce17c54a..3dc5694bb 100644 --- a/src/Service/S3/src/ValueObject/QueueConfiguration.php +++ b/src/Service/S3/src/ValueObject/QueueConfiguration.php @@ -37,8 +37,8 @@ final class QueueConfiguration public function __construct(array $input) { $this->id = $input['Id'] ?? null; - $this->queueArn = $input['QueueArn'] ?? null; - $this->events = $input['Events'] ?? null; + $this->queueArn = $input['QueueArn'] ?? $this->throwException(new InvalidArgument('Missing required field "QueueArn".')); + $this->events = $input['Events'] ?? $this->throwException(new InvalidArgument('Missing required field "Events".')); $this->filter = isset($input['Filter']) ? NotificationConfigurationFilter::create($input['Filter']) : null; } @@ -60,7 +60,7 @@ public static function create($input): self */ public function getEvents(): array { - return $this->events ?? []; + return $this->events; } public function getFilter(): ?NotificationConfigurationFilter @@ -86,13 +86,9 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void if (null !== $v = $this->id) { $node->appendChild($document->createElement('Id', $v)); } - if (null === $v = $this->queueArn) { - throw new InvalidArgument(sprintf('Missing parameter "QueueArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->queueArn; $node->appendChild($document->createElement('Queue', $v)); - if (null === $v = $this->events) { - throw new InvalidArgument(sprintf('Missing parameter "Events" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->events; foreach ($v as $item) { if (!Event::exists($item)) { throw new InvalidArgument(sprintf('Invalid parameter "Event" for "%s". The value "%s" is not a valid "Event".', __CLASS__, $item)); @@ -106,4 +102,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $v->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/ServerSideEncryptionByDefault.php b/src/Service/S3/src/ValueObject/ServerSideEncryptionByDefault.php index c2adab5b3..186fd138f 100644 --- a/src/Service/S3/src/ValueObject/ServerSideEncryptionByDefault.php +++ b/src/Service/S3/src/ValueObject/ServerSideEncryptionByDefault.php @@ -2,6 +2,7 @@ namespace AsyncAws\S3\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; use AsyncAws\S3\Enum\ServerSideEncryption; /** @@ -49,7 +50,7 @@ final class ServerSideEncryptionByDefault */ public function __construct(array $input) { - $this->sseAlgorithm = $input['SSEAlgorithm'] ?? null; + $this->sseAlgorithm = $input['SSEAlgorithm'] ?? $this->throwException(new InvalidArgument('Missing required field "SSEAlgorithm".')); $this->kmsMasterKeyId = $input['KMSMasterKeyID'] ?? null; } @@ -76,4 +77,12 @@ public function getSseAlgorithm(): string { return $this->sseAlgorithm; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/ServerSideEncryptionConfiguration.php b/src/Service/S3/src/ValueObject/ServerSideEncryptionConfiguration.php index f5d1d9eed..f5035ea73 100644 --- a/src/Service/S3/src/ValueObject/ServerSideEncryptionConfiguration.php +++ b/src/Service/S3/src/ValueObject/ServerSideEncryptionConfiguration.php @@ -2,6 +2,8 @@ namespace AsyncAws\S3\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Specifies the default server-side-encryption configuration. */ @@ -19,7 +21,7 @@ final class ServerSideEncryptionConfiguration */ public function __construct(array $input) { - $this->rules = isset($input['Rules']) ? array_map([ServerSideEncryptionRule::class, 'create'], $input['Rules']) : null; + $this->rules = isset($input['Rules']) ? array_map([ServerSideEncryptionRule::class, 'create'], $input['Rules']) : $this->throwException(new InvalidArgument('Missing required field "Rules".')); } /** @@ -37,6 +39,14 @@ public static function create($input): self */ public function getRules(): array { - return $this->rules ?? []; + return $this->rules; + } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; } } diff --git a/src/Service/S3/src/ValueObject/Tag.php b/src/Service/S3/src/ValueObject/Tag.php index 64b34ec8e..3cc4c19eb 100644 --- a/src/Service/S3/src/ValueObject/Tag.php +++ b/src/Service/S3/src/ValueObject/Tag.php @@ -27,8 +27,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -57,13 +57,17 @@ public function getValue(): string */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $node->appendChild($document->createElement('Key', $v)); - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $node->appendChild($document->createElement('Value', $v)); } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/Tagging.php b/src/Service/S3/src/ValueObject/Tagging.php index f6a5e8614..25fdddf4c 100644 --- a/src/Service/S3/src/ValueObject/Tagging.php +++ b/src/Service/S3/src/ValueObject/Tagging.php @@ -21,7 +21,7 @@ final class Tagging */ public function __construct(array $input) { - $this->tagSet = isset($input['TagSet']) ? array_map([Tag::class, 'create'], $input['TagSet']) : null; + $this->tagSet = isset($input['TagSet']) ? array_map([Tag::class, 'create'], $input['TagSet']) : $this->throwException(new InvalidArgument('Missing required field "TagSet".')); } /** @@ -39,7 +39,7 @@ public static function create($input): self */ public function getTagSet(): array { - return $this->tagSet ?? []; + return $this->tagSet; } /** @@ -47,9 +47,7 @@ public function getTagSet(): array */ public function requestBody(\DOMElement $node, \DOMDocument $document): void { - if (null === $v = $this->tagSet) { - throw new InvalidArgument(sprintf('Missing parameter "TagSet" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->tagSet; $node->appendChild($nodeList = $document->createElement('TagSet')); foreach ($v as $item) { @@ -58,4 +56,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $item->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/S3/src/ValueObject/TopicConfiguration.php b/src/Service/S3/src/ValueObject/TopicConfiguration.php index 06dc19bba..ae4f4ef31 100644 --- a/src/Service/S3/src/ValueObject/TopicConfiguration.php +++ b/src/Service/S3/src/ValueObject/TopicConfiguration.php @@ -40,8 +40,8 @@ final class TopicConfiguration public function __construct(array $input) { $this->id = $input['Id'] ?? null; - $this->topicArn = $input['TopicArn'] ?? null; - $this->events = $input['Events'] ?? null; + $this->topicArn = $input['TopicArn'] ?? $this->throwException(new InvalidArgument('Missing required field "TopicArn".')); + $this->events = $input['Events'] ?? $this->throwException(new InvalidArgument('Missing required field "Events".')); $this->filter = isset($input['Filter']) ? NotificationConfigurationFilter::create($input['Filter']) : null; } @@ -63,7 +63,7 @@ public static function create($input): self */ public function getEvents(): array { - return $this->events ?? []; + return $this->events; } public function getFilter(): ?NotificationConfigurationFilter @@ -89,13 +89,9 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void if (null !== $v = $this->id) { $node->appendChild($document->createElement('Id', $v)); } - if (null === $v = $this->topicArn) { - throw new InvalidArgument(sprintf('Missing parameter "TopicArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->topicArn; $node->appendChild($document->createElement('Topic', $v)); - if (null === $v = $this->events) { - throw new InvalidArgument(sprintf('Missing parameter "Events" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->events; foreach ($v as $item) { if (!Event::exists($item)) { throw new InvalidArgument(sprintf('Invalid parameter "Event" for "%s". The value "%s" is not a valid "Event".', __CLASS__, $item)); @@ -109,4 +105,12 @@ public function requestBody(\DOMElement $node, \DOMDocument $document): void $v->requestBody($child, $document); } } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/AwsVpcConfiguration.php b/src/Service/Scheduler/src/ValueObject/AwsVpcConfiguration.php index dd7f1d5d6..24cccfdb6 100644 --- a/src/Service/Scheduler/src/ValueObject/AwsVpcConfiguration.php +++ b/src/Service/Scheduler/src/ValueObject/AwsVpcConfiguration.php @@ -41,7 +41,7 @@ public function __construct(array $input) { $this->assignPublicIp = $input['AssignPublicIp'] ?? null; $this->securityGroups = $input['SecurityGroups'] ?? null; - $this->subnets = $input['Subnets'] ?? null; + $this->subnets = $input['Subnets'] ?? $this->throwException(new InvalidArgument('Missing required field "Subnets".')); } /** @@ -77,7 +77,7 @@ public function getSecurityGroups(): array */ public function getSubnets(): array { - return $this->subnets ?? []; + return $this->subnets; } /** @@ -100,9 +100,7 @@ public function requestBody(): array $payload['SecurityGroups'][$index] = $listValue; } } - if (null === $v = $this->subnets) { - throw new InvalidArgument(sprintf('Missing parameter "Subnets" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->subnets; $index = -1; $payload['Subnets'] = []; @@ -113,4 +111,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/CapacityProviderStrategyItem.php b/src/Service/Scheduler/src/ValueObject/CapacityProviderStrategyItem.php index c7615eded..a705d8a29 100644 --- a/src/Service/Scheduler/src/ValueObject/CapacityProviderStrategyItem.php +++ b/src/Service/Scheduler/src/ValueObject/CapacityProviderStrategyItem.php @@ -38,7 +38,7 @@ final class CapacityProviderStrategyItem public function __construct(array $input) { $this->base = $input['base'] ?? null; - $this->capacityProvider = $input['capacityProvider'] ?? null; + $this->capacityProvider = $input['capacityProvider'] ?? $this->throwException(new InvalidArgument('Missing required field "capacityProvider".')); $this->weight = $input['weight'] ?? null; } @@ -78,9 +78,7 @@ public function requestBody(): array if (null !== $v = $this->base) { $payload['base'] = $v; } - if (null === $v = $this->capacityProvider) { - throw new InvalidArgument(sprintf('Missing parameter "capacityProvider" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->capacityProvider; $payload['capacityProvider'] = $v; if (null !== $v = $this->weight) { $payload['weight'] = $v; @@ -88,4 +86,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/EcsParameters.php b/src/Service/Scheduler/src/ValueObject/EcsParameters.php index 06545e1e4..ad7654257 100644 --- a/src/Service/Scheduler/src/ValueObject/EcsParameters.php +++ b/src/Service/Scheduler/src/ValueObject/EcsParameters.php @@ -134,7 +134,7 @@ public function __construct(array $input) $this->referenceId = $input['ReferenceId'] ?? null; $this->tags = $input['Tags'] ?? null; $this->taskCount = $input['TaskCount'] ?? null; - $this->taskDefinitionArn = $input['TaskDefinitionArn'] ?? null; + $this->taskDefinitionArn = $input['TaskDefinitionArn'] ?? $this->throwException(new InvalidArgument('Missing required field "TaskDefinitionArn".')); } /** @@ -327,11 +327,17 @@ public function requestBody(): array if (null !== $v = $this->taskCount) { $payload['TaskCount'] = $v; } - if (null === $v = $this->taskDefinitionArn) { - throw new InvalidArgument(sprintf('Missing parameter "TaskDefinitionArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->taskDefinitionArn; $payload['TaskDefinitionArn'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/EventBridgeParameters.php b/src/Service/Scheduler/src/ValueObject/EventBridgeParameters.php index bb030b47d..592af3612 100644 --- a/src/Service/Scheduler/src/ValueObject/EventBridgeParameters.php +++ b/src/Service/Scheduler/src/ValueObject/EventBridgeParameters.php @@ -29,8 +29,8 @@ final class EventBridgeParameters */ public function __construct(array $input) { - $this->detailType = $input['DetailType'] ?? null; - $this->source = $input['Source'] ?? null; + $this->detailType = $input['DetailType'] ?? $this->throwException(new InvalidArgument('Missing required field "DetailType".')); + $this->source = $input['Source'] ?? $this->throwException(new InvalidArgument('Missing required field "Source".')); } /** @@ -60,15 +60,19 @@ public function getSource(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->detailType) { - throw new InvalidArgument(sprintf('Missing parameter "DetailType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->detailType; $payload['DetailType'] = $v; - if (null === $v = $this->source) { - throw new InvalidArgument(sprintf('Missing parameter "Source" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->source; $payload['Source'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/FlexibleTimeWindow.php b/src/Service/Scheduler/src/ValueObject/FlexibleTimeWindow.php index 2a9ddad56..c0f4e0951 100644 --- a/src/Service/Scheduler/src/ValueObject/FlexibleTimeWindow.php +++ b/src/Service/Scheduler/src/ValueObject/FlexibleTimeWindow.php @@ -29,7 +29,7 @@ final class FlexibleTimeWindow public function __construct(array $input) { $this->maximumWindowInMinutes = $input['MaximumWindowInMinutes'] ?? null; - $this->mode = $input['Mode'] ?? null; + $this->mode = $input['Mode'] ?? $this->throwException(new InvalidArgument('Missing required field "Mode".')); } /** @@ -65,9 +65,7 @@ public function requestBody(): array if (null !== $v = $this->maximumWindowInMinutes) { $payload['MaximumWindowInMinutes'] = $v; } - if (null === $v = $this->mode) { - throw new InvalidArgument(sprintf('Missing parameter "Mode" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->mode; if (!FlexibleTimeWindowMode::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "Mode" for "%s". The value "%s" is not a valid "FlexibleTimeWindowMode".', __CLASS__, $v)); } @@ -75,4 +73,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/KinesisParameters.php b/src/Service/Scheduler/src/ValueObject/KinesisParameters.php index fd4e4831a..6f1877b3f 100644 --- a/src/Service/Scheduler/src/ValueObject/KinesisParameters.php +++ b/src/Service/Scheduler/src/ValueObject/KinesisParameters.php @@ -26,7 +26,7 @@ final class KinesisParameters */ public function __construct(array $input) { - $this->partitionKey = $input['PartitionKey'] ?? null; + $this->partitionKey = $input['PartitionKey'] ?? $this->throwException(new InvalidArgument('Missing required field "PartitionKey".')); } /** @@ -50,11 +50,17 @@ public function getPartitionKey(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->partitionKey) { - throw new InvalidArgument(sprintf('Missing parameter "PartitionKey" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->partitionKey; $payload['PartitionKey'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/SageMakerPipelineParameter.php b/src/Service/Scheduler/src/ValueObject/SageMakerPipelineParameter.php index 09958504a..6bdf510ac 100644 --- a/src/Service/Scheduler/src/ValueObject/SageMakerPipelineParameter.php +++ b/src/Service/Scheduler/src/ValueObject/SageMakerPipelineParameter.php @@ -27,8 +27,8 @@ final class SageMakerPipelineParameter */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->value = $input['Value'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -58,15 +58,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/Tag.php b/src/Service/Scheduler/src/ValueObject/Tag.php index 95bf11a57..dba0a1c1c 100644 --- a/src/Service/Scheduler/src/ValueObject/Tag.php +++ b/src/Service/Scheduler/src/ValueObject/Tag.php @@ -27,8 +27,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -58,15 +58,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/Target.php b/src/Service/Scheduler/src/ValueObject/Target.php index ab6990d68..c30b92a9f 100644 --- a/src/Service/Scheduler/src/ValueObject/Target.php +++ b/src/Service/Scheduler/src/ValueObject/Target.php @@ -98,14 +98,14 @@ final class Target */ public function __construct(array $input) { - $this->arn = $input['Arn'] ?? null; + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); $this->deadLetterConfig = isset($input['DeadLetterConfig']) ? DeadLetterConfig::create($input['DeadLetterConfig']) : null; $this->ecsParameters = isset($input['EcsParameters']) ? EcsParameters::create($input['EcsParameters']) : null; $this->eventBridgeParameters = isset($input['EventBridgeParameters']) ? EventBridgeParameters::create($input['EventBridgeParameters']) : null; $this->input = $input['Input'] ?? null; $this->kinesisParameters = isset($input['KinesisParameters']) ? KinesisParameters::create($input['KinesisParameters']) : null; $this->retryPolicy = isset($input['RetryPolicy']) ? RetryPolicy::create($input['RetryPolicy']) : null; - $this->roleArn = $input['RoleArn'] ?? null; + $this->roleArn = $input['RoleArn'] ?? $this->throwException(new InvalidArgument('Missing required field "RoleArn".')); $this->sageMakerPipelineParameters = isset($input['SageMakerPipelineParameters']) ? SageMakerPipelineParameters::create($input['SageMakerPipelineParameters']) : null; $this->sqsParameters = isset($input['SqsParameters']) ? SqsParameters::create($input['SqsParameters']) : null; } @@ -185,9 +185,7 @@ public function getSqsParameters(): ?SqsParameters public function requestBody(): array { $payload = []; - if (null === $v = $this->arn) { - throw new InvalidArgument(sprintf('Missing parameter "Arn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->arn; $payload['Arn'] = $v; if (null !== $v = $this->deadLetterConfig) { $payload['DeadLetterConfig'] = $v->requestBody(); @@ -207,9 +205,7 @@ public function requestBody(): array if (null !== $v = $this->retryPolicy) { $payload['RetryPolicy'] = $v->requestBody(); } - if (null === $v = $this->roleArn) { - throw new InvalidArgument(sprintf('Missing parameter "RoleArn" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->roleArn; $payload['RoleArn'] = $v; if (null !== $v = $this->sageMakerPipelineParameters) { $payload['SageMakerPipelineParameters'] = $v->requestBody(); @@ -220,4 +216,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Scheduler/src/ValueObject/TargetSummary.php b/src/Service/Scheduler/src/ValueObject/TargetSummary.php index 9b22a9346..6a0365241 100644 --- a/src/Service/Scheduler/src/ValueObject/TargetSummary.php +++ b/src/Service/Scheduler/src/ValueObject/TargetSummary.php @@ -2,6 +2,8 @@ namespace AsyncAws\Scheduler\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The details of a target. */ @@ -19,7 +21,7 @@ final class TargetSummary */ public function __construct(array $input) { - $this->arn = $input['Arn'] ?? null; + $this->arn = $input['Arn'] ?? $this->throwException(new InvalidArgument('Missing required field "Arn".')); } /** @@ -36,4 +38,12 @@ public function getArn(): string { return $this->arn; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ses/src/ValueObject/Content.php b/src/Service/Ses/src/ValueObject/Content.php index 74b93a8b2..e1982f823 100644 --- a/src/Service/Ses/src/ValueObject/Content.php +++ b/src/Service/Ses/src/ValueObject/Content.php @@ -29,7 +29,7 @@ final class Content */ public function __construct(array $input) { - $this->data = $input['Data'] ?? null; + $this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".')); $this->charset = $input['Charset'] ?? null; } @@ -60,9 +60,7 @@ public function getData(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->data) { - throw new InvalidArgument(sprintf('Missing parameter "Data" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->data; $payload['Data'] = $v; if (null !== $v = $this->charset) { $payload['Charset'] = $v; @@ -70,4 +68,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ses/src/ValueObject/ListManagementOptions.php b/src/Service/Ses/src/ValueObject/ListManagementOptions.php index 0e4eead09..4eb235b35 100644 --- a/src/Service/Ses/src/ValueObject/ListManagementOptions.php +++ b/src/Service/Ses/src/ValueObject/ListManagementOptions.php @@ -28,7 +28,7 @@ final class ListManagementOptions */ public function __construct(array $input) { - $this->contactListName = $input['ContactListName'] ?? null; + $this->contactListName = $input['ContactListName'] ?? $this->throwException(new InvalidArgument('Missing required field "ContactListName".')); $this->topicName = $input['TopicName'] ?? null; } @@ -59,9 +59,7 @@ public function getTopicName(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->contactListName) { - throw new InvalidArgument(sprintf('Missing parameter "ContactListName" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->contactListName; $payload['ContactListName'] = $v; if (null !== $v = $this->topicName) { $payload['TopicName'] = $v; @@ -69,4 +67,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ses/src/ValueObject/Message.php b/src/Service/Ses/src/ValueObject/Message.php index 313fe3600..0435e39ef 100644 --- a/src/Service/Ses/src/ValueObject/Message.php +++ b/src/Service/Ses/src/ValueObject/Message.php @@ -30,8 +30,8 @@ final class Message */ public function __construct(array $input) { - $this->subject = isset($input['Subject']) ? Content::create($input['Subject']) : null; - $this->body = isset($input['Body']) ? Body::create($input['Body']) : null; + $this->subject = isset($input['Subject']) ? Content::create($input['Subject']) : $this->throwException(new InvalidArgument('Missing required field "Subject".')); + $this->body = isset($input['Body']) ? Body::create($input['Body']) : $this->throwException(new InvalidArgument('Missing required field "Body".')); } /** @@ -61,15 +61,19 @@ public function getSubject(): Content public function requestBody(): array { $payload = []; - if (null === $v = $this->subject) { - throw new InvalidArgument(sprintf('Missing parameter "Subject" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->subject; $payload['Subject'] = $v->requestBody(); - if (null === $v = $this->body) { - throw new InvalidArgument(sprintf('Missing parameter "Body" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->body; $payload['Body'] = $v->requestBody(); return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ses/src/ValueObject/MessageTag.php b/src/Service/Ses/src/ValueObject/MessageTag.php index 0060ad2d0..b94c8d53e 100644 --- a/src/Service/Ses/src/ValueObject/MessageTag.php +++ b/src/Service/Ses/src/ValueObject/MessageTag.php @@ -34,8 +34,8 @@ final class MessageTag */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->value = $input['Value'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -65,15 +65,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ses/src/ValueObject/RawMessage.php b/src/Service/Ses/src/ValueObject/RawMessage.php index 8c3879f40..746c6c5db 100644 --- a/src/Service/Ses/src/ValueObject/RawMessage.php +++ b/src/Service/Ses/src/ValueObject/RawMessage.php @@ -33,7 +33,7 @@ final class RawMessage */ public function __construct(array $input) { - $this->data = $input['Data'] ?? null; + $this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".')); } /** @@ -57,11 +57,17 @@ public function getData(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->data) { - throw new InvalidArgument(sprintf('Missing parameter "Data" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->data; $payload['Data'] = base64_encode($v); return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sns/src/ValueObject/BatchResultErrorEntry.php b/src/Service/Sns/src/ValueObject/BatchResultErrorEntry.php index b20150e24..989a2b137 100644 --- a/src/Service/Sns/src/ValueObject/BatchResultErrorEntry.php +++ b/src/Service/Sns/src/ValueObject/BatchResultErrorEntry.php @@ -2,6 +2,8 @@ namespace AsyncAws\Sns\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Gives a detailed description of failed messages in the batch. */ @@ -37,10 +39,10 @@ final class BatchResultErrorEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->code = $input['Code'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->code = $input['Code'] ?? $this->throwException(new InvalidArgument('Missing required field "Code".')); $this->message = $input['Message'] ?? null; - $this->senderFault = $input['SenderFault'] ?? null; + $this->senderFault = $input['SenderFault'] ?? $this->throwException(new InvalidArgument('Missing required field "SenderFault".')); } /** @@ -75,4 +77,12 @@ public function getSenderFault(): bool { return $this->senderFault; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sns/src/ValueObject/MessageAttributeValue.php b/src/Service/Sns/src/ValueObject/MessageAttributeValue.php index 5c5192a5e..d418d8686 100644 --- a/src/Service/Sns/src/ValueObject/MessageAttributeValue.php +++ b/src/Service/Sns/src/ValueObject/MessageAttributeValue.php @@ -48,7 +48,7 @@ final class MessageAttributeValue */ public function __construct(array $input) { - $this->dataType = $input['DataType'] ?? null; + $this->dataType = $input['DataType'] ?? $this->throwException(new InvalidArgument('Missing required field "DataType".')); $this->stringValue = $input['StringValue'] ?? null; $this->binaryValue = $input['BinaryValue'] ?? null; } @@ -86,9 +86,7 @@ public function getStringValue(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->dataType) { - throw new InvalidArgument(sprintf('Missing parameter "DataType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->dataType; $payload['DataType'] = $v; if (null !== $v = $this->stringValue) { $payload['StringValue'] = $v; @@ -99,4 +97,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sns/src/ValueObject/PublishBatchRequestEntry.php b/src/Service/Sns/src/ValueObject/PublishBatchRequestEntry.php index 83fd03ba5..8f692d54d 100644 --- a/src/Service/Sns/src/ValueObject/PublishBatchRequestEntry.php +++ b/src/Service/Sns/src/ValueObject/PublishBatchRequestEntry.php @@ -122,8 +122,8 @@ final class PublishBatchRequestEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->message = $input['Message'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->message = $input['Message'] ?? $this->throwException(new InvalidArgument('Missing required field "Message".')); $this->subject = $input['Subject'] ?? null; $this->messageStructure = $input['MessageStructure'] ?? null; $this->messageAttributes = isset($input['MessageAttributes']) ? array_map([MessageAttributeValue::class, 'create'], $input['MessageAttributes']) : null; @@ -191,13 +191,9 @@ public function getSubject(): ?string public function requestBody(): array { $payload = []; - if (null === $v = $this->id) { - throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->id; $payload['Id'] = $v; - if (null === $v = $this->message) { - throw new InvalidArgument(sprintf('Missing parameter "Message" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->message; $payload['Message'] = $v; if (null !== $v = $this->subject) { $payload['Subject'] = $v; @@ -224,4 +220,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sns/src/ValueObject/Tag.php b/src/Service/Sns/src/ValueObject/Tag.php index 81ed35a8a..d4d6527d8 100644 --- a/src/Service/Sns/src/ValueObject/Tag.php +++ b/src/Service/Sns/src/ValueObject/Tag.php @@ -27,8 +27,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -58,15 +58,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/BatchResultErrorEntry.php b/src/Service/Sqs/src/ValueObject/BatchResultErrorEntry.php index 0bb24a59f..1ffbc8c74 100644 --- a/src/Service/Sqs/src/ValueObject/BatchResultErrorEntry.php +++ b/src/Service/Sqs/src/ValueObject/BatchResultErrorEntry.php @@ -2,6 +2,8 @@ namespace AsyncAws\Sqs\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Gives a detailed description of the result of an action on each entry in the request. */ @@ -37,9 +39,9 @@ final class BatchResultErrorEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->senderFault = $input['SenderFault'] ?? null; - $this->code = $input['Code'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->senderFault = $input['SenderFault'] ?? $this->throwException(new InvalidArgument('Missing required field "SenderFault".')); + $this->code = $input['Code'] ?? $this->throwException(new InvalidArgument('Missing required field "Code".')); $this->message = $input['Message'] ?? null; } @@ -75,4 +77,12 @@ public function getSenderFault(): bool { return $this->senderFault; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchRequestEntry.php b/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchRequestEntry.php index 52524cbf2..4804170a9 100644 --- a/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchRequestEntry.php +++ b/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchRequestEntry.php @@ -38,8 +38,8 @@ final class ChangeMessageVisibilityBatchRequestEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->receiptHandle = $input['ReceiptHandle'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->receiptHandle = $input['ReceiptHandle'] ?? $this->throwException(new InvalidArgument('Missing required field "ReceiptHandle".')); $this->visibilityTimeout = $input['VisibilityTimeout'] ?? null; } @@ -76,13 +76,9 @@ public function getVisibilityTimeout(): ?int public function requestBody(): array { $payload = []; - if (null === $v = $this->id) { - throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->id; $payload['Id'] = $v; - if (null === $v = $this->receiptHandle) { - throw new InvalidArgument(sprintf('Missing parameter "ReceiptHandle" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->receiptHandle; $payload['ReceiptHandle'] = $v; if (null !== $v = $this->visibilityTimeout) { $payload['VisibilityTimeout'] = $v; @@ -90,4 +86,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchResultEntry.php b/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchResultEntry.php index 0095972de..97f7680c0 100644 --- a/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchResultEntry.php +++ b/src/Service/Sqs/src/ValueObject/ChangeMessageVisibilityBatchResultEntry.php @@ -2,6 +2,8 @@ namespace AsyncAws\Sqs\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Encloses the `Id` of an entry in `ChangeMessageVisibilityBatch.`. */ @@ -19,7 +21,7 @@ final class ChangeMessageVisibilityBatchResultEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); } /** @@ -36,4 +38,12 @@ public function getId(): string { return $this->id; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/DeleteMessageBatchRequestEntry.php b/src/Service/Sqs/src/ValueObject/DeleteMessageBatchRequestEntry.php index 5bc3e7e3c..cb668b17a 100644 --- a/src/Service/Sqs/src/ValueObject/DeleteMessageBatchRequestEntry.php +++ b/src/Service/Sqs/src/ValueObject/DeleteMessageBatchRequestEntry.php @@ -32,8 +32,8 @@ final class DeleteMessageBatchRequestEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->receiptHandle = $input['ReceiptHandle'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->receiptHandle = $input['ReceiptHandle'] ?? $this->throwException(new InvalidArgument('Missing required field "ReceiptHandle".')); } /** @@ -63,15 +63,19 @@ public function getReceiptHandle(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->id) { - throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->id; $payload['Id'] = $v; - if (null === $v = $this->receiptHandle) { - throw new InvalidArgument(sprintf('Missing parameter "ReceiptHandle" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->receiptHandle; $payload['ReceiptHandle'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/DeleteMessageBatchResultEntry.php b/src/Service/Sqs/src/ValueObject/DeleteMessageBatchResultEntry.php index 964d554d4..4bc4a8842 100644 --- a/src/Service/Sqs/src/ValueObject/DeleteMessageBatchResultEntry.php +++ b/src/Service/Sqs/src/ValueObject/DeleteMessageBatchResultEntry.php @@ -2,6 +2,8 @@ namespace AsyncAws\Sqs\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Encloses the `Id` of an entry in `DeleteMessageBatch.`. */ @@ -19,7 +21,7 @@ final class DeleteMessageBatchResultEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); } /** @@ -36,4 +38,12 @@ public function getId(): string { return $this->id; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/MessageAttributeValue.php b/src/Service/Sqs/src/ValueObject/MessageAttributeValue.php index 602f252f7..e10d6dd3b 100644 --- a/src/Service/Sqs/src/ValueObject/MessageAttributeValue.php +++ b/src/Service/Sqs/src/ValueObject/MessageAttributeValue.php @@ -61,7 +61,7 @@ public function __construct(array $input) $this->binaryValue = $input['BinaryValue'] ?? null; $this->stringListValues = $input['StringListValues'] ?? null; $this->binaryListValues = $input['BinaryListValues'] ?? null; - $this->dataType = $input['DataType'] ?? null; + $this->dataType = $input['DataType'] ?? $this->throwException(new InvalidArgument('Missing required field "DataType".')); } /** @@ -135,11 +135,17 @@ public function requestBody(): array $payload["BinaryListValue.$index"] = base64_encode($mapValue); } } - if (null === $v = $this->dataType) { - throw new InvalidArgument(sprintf('Missing parameter "DataType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->dataType; $payload['DataType'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/MessageSystemAttributeValue.php b/src/Service/Sqs/src/ValueObject/MessageSystemAttributeValue.php index 4f88c16ee..fa51bae10 100644 --- a/src/Service/Sqs/src/ValueObject/MessageSystemAttributeValue.php +++ b/src/Service/Sqs/src/ValueObject/MessageSystemAttributeValue.php @@ -60,7 +60,7 @@ public function __construct(array $input) $this->binaryValue = $input['BinaryValue'] ?? null; $this->stringListValues = $input['StringListValues'] ?? null; $this->binaryListValues = $input['BinaryListValues'] ?? null; - $this->dataType = $input['DataType'] ?? null; + $this->dataType = $input['DataType'] ?? $this->throwException(new InvalidArgument('Missing required field "DataType".')); } /** @@ -134,11 +134,17 @@ public function requestBody(): array $payload["BinaryListValue.$index"] = base64_encode($mapValue); } } - if (null === $v = $this->dataType) { - throw new InvalidArgument(sprintf('Missing parameter "DataType" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->dataType; $payload['DataType'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/SendMessageBatchRequestEntry.php b/src/Service/Sqs/src/ValueObject/SendMessageBatchRequestEntry.php index fac632964..18c05f59f 100644 --- a/src/Service/Sqs/src/ValueObject/SendMessageBatchRequestEntry.php +++ b/src/Service/Sqs/src/ValueObject/SendMessageBatchRequestEntry.php @@ -135,8 +135,8 @@ final class SendMessageBatchRequestEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->messageBody = $input['MessageBody'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->messageBody = $input['MessageBody'] ?? $this->throwException(new InvalidArgument('Missing required field "MessageBody".')); $this->delaySeconds = $input['DelaySeconds'] ?? null; $this->messageAttributes = isset($input['MessageAttributes']) ? array_map([MessageAttributeValue::class, 'create'], $input['MessageAttributes']) : null; $this->messageSystemAttributes = isset($input['MessageSystemAttributes']) ? array_map([MessageSystemAttributeValue::class, 'create'], $input['MessageSystemAttributes']) : null; @@ -207,13 +207,9 @@ public function getMessageSystemAttributes(): array public function requestBody(): array { $payload = []; - if (null === $v = $this->id) { - throw new InvalidArgument(sprintf('Missing parameter "Id" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->id; $payload['Id'] = $v; - if (null === $v = $this->messageBody) { - throw new InvalidArgument(sprintf('Missing parameter "MessageBody" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->messageBody; $payload['MessageBody'] = $v; if (null !== $v = $this->delaySeconds) { $payload['DelaySeconds'] = $v; @@ -250,4 +246,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Sqs/src/ValueObject/SendMessageBatchResultEntry.php b/src/Service/Sqs/src/ValueObject/SendMessageBatchResultEntry.php index 6285ea08f..15c65d816 100644 --- a/src/Service/Sqs/src/ValueObject/SendMessageBatchResultEntry.php +++ b/src/Service/Sqs/src/ValueObject/SendMessageBatchResultEntry.php @@ -2,6 +2,8 @@ namespace AsyncAws\Sqs\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Encloses a `MessageId` for a successfully-enqueued message in a `SendMessageBatch.`. */ @@ -66,9 +68,9 @@ final class SendMessageBatchResultEntry */ public function __construct(array $input) { - $this->id = $input['Id'] ?? null; - $this->messageId = $input['MessageId'] ?? null; - $this->md5OfMessageBody = $input['MD5OfMessageBody'] ?? null; + $this->id = $input['Id'] ?? $this->throwException(new InvalidArgument('Missing required field "Id".')); + $this->messageId = $input['MessageId'] ?? $this->throwException(new InvalidArgument('Missing required field "MessageId".')); + $this->md5OfMessageBody = $input['MD5OfMessageBody'] ?? $this->throwException(new InvalidArgument('Missing required field "MD5OfMessageBody".')); $this->md5OfMessageAttributes = $input['MD5OfMessageAttributes'] ?? null; $this->md5OfMessageSystemAttributes = $input['MD5OfMessageSystemAttributes'] ?? null; $this->sequenceNumber = $input['SequenceNumber'] ?? null; @@ -118,4 +120,12 @@ public function getSequenceNumber(): ?string { return $this->sequenceNumber; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ssm/src/ValueObject/ParameterStringFilter.php b/src/Service/Ssm/src/ValueObject/ParameterStringFilter.php index eb5cbcb86..a694c6b5a 100644 --- a/src/Service/Ssm/src/ValueObject/ParameterStringFilter.php +++ b/src/Service/Ssm/src/ValueObject/ParameterStringFilter.php @@ -51,7 +51,7 @@ final class ParameterStringFilter */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); $this->option = $input['Option'] ?? null; $this->values = $input['Values'] ?? null; } @@ -92,9 +92,7 @@ public function getValues(): array public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; if (null !== $v = $this->option) { $payload['Option'] = $v; @@ -110,4 +108,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/Ssm/src/ValueObject/Tag.php b/src/Service/Ssm/src/ValueObject/Tag.php index 2d9b971f5..5ff2f1424 100644 --- a/src/Service/Ssm/src/ValueObject/Tag.php +++ b/src/Service/Ssm/src/ValueObject/Tag.php @@ -30,8 +30,8 @@ final class Tag */ public function __construct(array $input) { - $this->key = $input['Key'] ?? null; - $this->value = $input['Value'] ?? null; + $this->key = $input['Key'] ?? $this->throwException(new InvalidArgument('Missing required field "Key".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -61,15 +61,19 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->key) { - throw new InvalidArgument(sprintf('Missing parameter "Key" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->key; $payload['Key'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamQuery/src/ValueObject/ColumnInfo.php b/src/Service/TimestreamQuery/src/ValueObject/ColumnInfo.php index 1f72b4cd1..0eaf1712c 100644 --- a/src/Service/TimestreamQuery/src/ValueObject/ColumnInfo.php +++ b/src/Service/TimestreamQuery/src/ValueObject/ColumnInfo.php @@ -2,6 +2,8 @@ namespace AsyncAws\TimestreamQuery\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Contains the metadata for query results such as the column names, data types, and other attributes. */ @@ -28,7 +30,7 @@ final class ColumnInfo public function __construct(array $input) { $this->name = $input['Name'] ?? null; - $this->type = isset($input['Type']) ? Type::create($input['Type']) : null; + $this->type = isset($input['Type']) ? Type::create($input['Type']) : $this->throwException(new InvalidArgument('Missing required field "Type".')); } /** @@ -51,4 +53,12 @@ public function getType(): Type { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamQuery/src/ValueObject/Endpoint.php b/src/Service/TimestreamQuery/src/ValueObject/Endpoint.php index 23bddcf95..d7b361df7 100644 --- a/src/Service/TimestreamQuery/src/ValueObject/Endpoint.php +++ b/src/Service/TimestreamQuery/src/ValueObject/Endpoint.php @@ -3,6 +3,7 @@ namespace AsyncAws\TimestreamQuery\ValueObject; use AsyncAws\Core\EndpointDiscovery\EndpointInterface; +use AsyncAws\Core\Exception\InvalidArgument; /** * Represents an available endpoint against which to make API calls against, as well as the TTL for that endpoint. @@ -27,8 +28,8 @@ final class Endpoint implements EndpointInterface */ public function __construct(array $input) { - $this->address = $input['Address'] ?? null; - $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? null; + $this->address = $input['Address'] ?? $this->throwException(new InvalidArgument('Missing required field "Address".')); + $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? $this->throwException(new InvalidArgument('Missing required field "CachePeriodInMinutes".')); } /** @@ -51,4 +52,12 @@ public function getCachePeriodInMinutes(): int { return $this->cachePeriodInMinutes; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamQuery/src/ValueObject/ParameterMapping.php b/src/Service/TimestreamQuery/src/ValueObject/ParameterMapping.php index 43e049abb..36104916b 100644 --- a/src/Service/TimestreamQuery/src/ValueObject/ParameterMapping.php +++ b/src/Service/TimestreamQuery/src/ValueObject/ParameterMapping.php @@ -2,6 +2,8 @@ namespace AsyncAws\TimestreamQuery\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Mapping for named parameters. */ @@ -22,8 +24,8 @@ final class ParameterMapping */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->type = isset($input['Type']) ? Type::create($input['Type']) : null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->type = isset($input['Type']) ? Type::create($input['Type']) : $this->throwException(new InvalidArgument('Missing required field "Type".')); } /** @@ -46,4 +48,12 @@ public function getType(): Type { return $this->type; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamQuery/src/ValueObject/Row.php b/src/Service/TimestreamQuery/src/ValueObject/Row.php index 4927132a5..7bf522c61 100644 --- a/src/Service/TimestreamQuery/src/ValueObject/Row.php +++ b/src/Service/TimestreamQuery/src/ValueObject/Row.php @@ -2,6 +2,8 @@ namespace AsyncAws\TimestreamQuery\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * Represents a single row in the query results. */ @@ -19,7 +21,7 @@ final class Row */ public function __construct(array $input) { - $this->data = isset($input['Data']) ? array_map([Datum::class, 'create'], $input['Data']) : null; + $this->data = isset($input['Data']) ? array_map([Datum::class, 'create'], $input['Data']) : $this->throwException(new InvalidArgument('Missing required field "Data".')); } /** @@ -37,6 +39,14 @@ public static function create($input): self */ public function getData(): array { - return $this->data ?? []; + return $this->data; + } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; } } diff --git a/src/Service/TimestreamQuery/src/ValueObject/TimeSeriesDataPoint.php b/src/Service/TimestreamQuery/src/ValueObject/TimeSeriesDataPoint.php index b69730754..291120088 100644 --- a/src/Service/TimestreamQuery/src/ValueObject/TimeSeriesDataPoint.php +++ b/src/Service/TimestreamQuery/src/ValueObject/TimeSeriesDataPoint.php @@ -2,6 +2,8 @@ namespace AsyncAws\TimestreamQuery\ValueObject; +use AsyncAws\Core\Exception\InvalidArgument; + /** * The timeseries data type represents the values of a measure over time. A time series is an array of rows of * timestamps and measure values, with rows sorted in ascending order of time. A TimeSeriesDataPoint is a single data @@ -27,8 +29,8 @@ final class TimeSeriesDataPoint */ public function __construct(array $input) { - $this->time = $input['Time'] ?? null; - $this->value = isset($input['Value']) ? Datum::create($input['Value']) : null; + $this->time = $input['Time'] ?? $this->throwException(new InvalidArgument('Missing required field "Time".')); + $this->value = isset($input['Value']) ? Datum::create($input['Value']) : $this->throwException(new InvalidArgument('Missing required field "Value".')); } /** @@ -51,4 +53,12 @@ public function getValue(): Datum { return $this->value; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamWrite/src/ValueObject/Dimension.php b/src/Service/TimestreamWrite/src/ValueObject/Dimension.php index 47f6201d6..69cd0515a 100644 --- a/src/Service/TimestreamWrite/src/ValueObject/Dimension.php +++ b/src/Service/TimestreamWrite/src/ValueObject/Dimension.php @@ -40,8 +40,8 @@ final class Dimension */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->value = $input['Value'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); $this->dimensionValueType = $input['DimensionValueType'] ?? null; } @@ -81,13 +81,9 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; if (null !== $v = $this->dimensionValueType) { if (!DimensionValueType::exists($v)) { @@ -98,4 +94,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamWrite/src/ValueObject/Endpoint.php b/src/Service/TimestreamWrite/src/ValueObject/Endpoint.php index a99689e1c..1ffecfc34 100644 --- a/src/Service/TimestreamWrite/src/ValueObject/Endpoint.php +++ b/src/Service/TimestreamWrite/src/ValueObject/Endpoint.php @@ -3,6 +3,7 @@ namespace AsyncAws\TimestreamWrite\ValueObject; use AsyncAws\Core\EndpointDiscovery\EndpointInterface; +use AsyncAws\Core\Exception\InvalidArgument; /** * Represents an available endpoint against which to make API calls against, as well as the TTL for that endpoint. @@ -27,8 +28,8 @@ final class Endpoint implements EndpointInterface */ public function __construct(array $input) { - $this->address = $input['Address'] ?? null; - $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? null; + $this->address = $input['Address'] ?? $this->throwException(new InvalidArgument('Missing required field "Address".')); + $this->cachePeriodInMinutes = $input['CachePeriodInMinutes'] ?? $this->throwException(new InvalidArgument('Missing required field "CachePeriodInMinutes".')); } /** @@ -51,4 +52,12 @@ public function getCachePeriodInMinutes(): int { return $this->cachePeriodInMinutes; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } } diff --git a/src/Service/TimestreamWrite/src/ValueObject/MeasureValue.php b/src/Service/TimestreamWrite/src/ValueObject/MeasureValue.php index 919001fb5..6fc8c0041 100644 --- a/src/Service/TimestreamWrite/src/ValueObject/MeasureValue.php +++ b/src/Service/TimestreamWrite/src/ValueObject/MeasureValue.php @@ -44,9 +44,9 @@ final class MeasureValue */ public function __construct(array $input) { - $this->name = $input['Name'] ?? null; - $this->value = $input['Value'] ?? null; - $this->type = $input['Type'] ?? null; + $this->name = $input['Name'] ?? $this->throwException(new InvalidArgument('Missing required field "Name".')); + $this->value = $input['Value'] ?? $this->throwException(new InvalidArgument('Missing required field "Value".')); + $this->type = $input['Type'] ?? $this->throwException(new InvalidArgument('Missing required field "Type".')); } /** @@ -85,17 +85,11 @@ public function getValue(): string public function requestBody(): array { $payload = []; - if (null === $v = $this->name) { - throw new InvalidArgument(sprintf('Missing parameter "Name" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->name; $payload['Name'] = $v; - if (null === $v = $this->value) { - throw new InvalidArgument(sprintf('Missing parameter "Value" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->value; $payload['Value'] = $v; - if (null === $v = $this->type) { - throw new InvalidArgument(sprintf('Missing parameter "Type" for "%s". The value cannot be null.', __CLASS__)); - } + $v = $this->type; if (!MeasureValueType::exists($v)) { throw new InvalidArgument(sprintf('Invalid parameter "Type" for "%s". The value "%s" is not a valid "MeasureValueType".', __CLASS__, $v)); } @@ -103,4 +97,12 @@ public function requestBody(): array return $payload; } + + /** + * @return never + */ + private function throwException(\Throwable $exception) + { + throw $exception; + } }