diff --git a/psalm.baseline.xml b/psalm.baseline.xml index dc1e9afa9..efb8a422c 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -52,14 +52,4 @@ - - - - - - - - - - diff --git a/src/CodeGenerator/src/Generator/ResponseParser/JsonRpcParser.php b/src/CodeGenerator/src/Generator/ResponseParser/JsonRpcParser.php index 898f47b22..9e40e49be 100644 --- a/src/CodeGenerator/src/Generator/ResponseParser/JsonRpcParser.php +++ b/src/CodeGenerator/src/Generator/ResponseParser/JsonRpcParser.php @@ -16,7 +16,7 @@ class JsonRpcParser extends RestJsonParser protected function parseResponseTimestamp(Shape $shape, string $input, bool $required): string { if ($required) { - $body = '/** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat(\'U.u\', \sprintf(\'%.6F\', INPUT))'; + $body = $this->rejectUnparsableTimestamp('\DateTimeImmutable::createFromFormat(\'U.u\', \sprintf(\'%.6F\', INPUT))'); } else { $body = '(isset(INPUT) && ($d = \DateTimeImmutable::createFromFormat(\'U.u\', \sprintf(\'%.6F\', INPUT)))) ? $d : null'; } diff --git a/src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php b/src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php index e4939e2a8..23afbeb5f 100644 --- a/src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php +++ b/src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php @@ -19,6 +19,7 @@ use AsyncAws\CodeGenerator\Generator\GeneratorHelper; use AsyncAws\CodeGenerator\Generator\Naming\ClassName; use AsyncAws\CodeGenerator\Generator\Naming\NamespaceRegistry; +use AsyncAws\Core\Exception\UnparsableResponse; use Nette\PhpGenerator\Method; use Nette\PhpGenerator\Visibility; @@ -161,7 +162,7 @@ protected function parseResponseTimestamp(Shape $shape, string $input, bool $req } if ($required) { - $body = '/** @var \DateTimeImmutable $d */ $d = ' . $body; + $body = $this->rejectUnparsableTimestamp($body); } else { $body = 'isset(INPUT) && ($d = ' . $body . ') ? $d : null'; } @@ -169,6 +170,20 @@ protected function parseResponseTimestamp(Shape $shape, string $input, bool $req return strtr($body, ['INPUT' => $input]); } + /** + * createFromFormat() returns false on a malformed value, and no annotation convinces static + * analysis that it cannot happen here. The failure is raised instead, so that the generated + * code needs no baseline entry: the value comes from the response, which is exactly what + * UnparsableResponse describes. + */ + protected function rejectUnparsableTimestamp(string $body): string + { + $className = ClassName::createFromFqdn(UnparsableResponse::class); + $this->imports[] = $className; + + return $body . ' ?: throw new ' . $className->getName() . "('Invalid timestamp received.')"; + } + private function getInputAccessorName(Member $member): string { if ($member instanceof StructureMember) { diff --git a/src/Service/DynamoDb/CHANGELOG.md b/src/Service/DynamoDb/CHANGELOG.md index ec6071abd..f54864a96 100644 --- a/src/Service/DynamoDb/CHANGELOG.md +++ b/src/Service/DynamoDb/CHANGELOG.md @@ -6,6 +6,10 @@ - AWS api-change: Vector indexes are a type of index in Amazon DynamoDB that enable similarity search on vector embedding stored in your table items. Vector indexes use approximate nearest neighbor search to find items whose vectors are most similar to a query vector that you provide. +### Changed + +- Throw `UnparsableResponse` instead of a `TypeError` when a required timestamp cannot be parsed + ## 3.11.0 ### Added diff --git a/src/Service/DynamoDb/src/Result/CreateTableOutput.php b/src/Service/DynamoDb/src/Result/CreateTableOutput.php index 0d73796d9..c010ec4c6 100644 --- a/src/Service/DynamoDb/src/Result/CreateTableOutput.php +++ b/src/Service/DynamoDb/src/Result/CreateTableOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\DynamoDb\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\DynamoDb\Enum\BillingMode; @@ -332,7 +333,7 @@ private function populateResultRestoreSummary(array $json): RestoreSummary return new RestoreSummary([ 'SourceBackupArn' => isset($json['SourceBackupArn']) ? (string) $json['SourceBackupArn'] : null, 'SourceTableArn' => isset($json['SourceTableArn']) ? (string) $json['SourceTableArn'] : null, - 'RestoreDateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])), + 'RestoreDateTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'RestoreInProgress' => filter_var($json['RestoreInProgress'], \FILTER_VALIDATE_BOOLEAN), ]); } diff --git a/src/Service/DynamoDb/src/Result/DeleteTableOutput.php b/src/Service/DynamoDb/src/Result/DeleteTableOutput.php index 69c0832e4..e927522d6 100644 --- a/src/Service/DynamoDb/src/Result/DeleteTableOutput.php +++ b/src/Service/DynamoDb/src/Result/DeleteTableOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\DynamoDb\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\DynamoDb\Enum\BillingMode; @@ -332,7 +333,7 @@ private function populateResultRestoreSummary(array $json): RestoreSummary return new RestoreSummary([ 'SourceBackupArn' => isset($json['SourceBackupArn']) ? (string) $json['SourceBackupArn'] : null, 'SourceTableArn' => isset($json['SourceTableArn']) ? (string) $json['SourceTableArn'] : null, - 'RestoreDateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])), + 'RestoreDateTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'RestoreInProgress' => filter_var($json['RestoreInProgress'], \FILTER_VALIDATE_BOOLEAN), ]); } diff --git a/src/Service/DynamoDb/src/Result/DescribeTableOutput.php b/src/Service/DynamoDb/src/Result/DescribeTableOutput.php index b54a59613..1d7973171 100644 --- a/src/Service/DynamoDb/src/Result/DescribeTableOutput.php +++ b/src/Service/DynamoDb/src/Result/DescribeTableOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\DynamoDb\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\DynamoDb\Enum\BillingMode; @@ -332,7 +333,7 @@ private function populateResultRestoreSummary(array $json): RestoreSummary return new RestoreSummary([ 'SourceBackupArn' => isset($json['SourceBackupArn']) ? (string) $json['SourceBackupArn'] : null, 'SourceTableArn' => isset($json['SourceTableArn']) ? (string) $json['SourceTableArn'] : null, - 'RestoreDateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])), + 'RestoreDateTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'RestoreInProgress' => filter_var($json['RestoreInProgress'], \FILTER_VALIDATE_BOOLEAN), ]); } diff --git a/src/Service/DynamoDb/src/Result/UpdateTableOutput.php b/src/Service/DynamoDb/src/Result/UpdateTableOutput.php index 870c7078c..f257b2dfc 100644 --- a/src/Service/DynamoDb/src/Result/UpdateTableOutput.php +++ b/src/Service/DynamoDb/src/Result/UpdateTableOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\DynamoDb\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\DynamoDb\Enum\BillingMode; @@ -332,7 +333,7 @@ private function populateResultRestoreSummary(array $json): RestoreSummary return new RestoreSummary([ 'SourceBackupArn' => isset($json['SourceBackupArn']) ? (string) $json['SourceBackupArn'] : null, 'SourceTableArn' => isset($json['SourceTableArn']) ? (string) $json['SourceTableArn'] : null, - 'RestoreDateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])), + 'RestoreDateTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['RestoreDateTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'RestoreInProgress' => filter_var($json['RestoreInProgress'], \FILTER_VALIDATE_BOOLEAN), ]); } diff --git a/src/Service/Kinesis/CHANGELOG.md b/src/Service/Kinesis/CHANGELOG.md index 711d9cd82..e26392adf 100644 --- a/src/Service/Kinesis/CHANGELOG.md +++ b/src/Service/Kinesis/CHANGELOG.md @@ -9,6 +9,7 @@ ### Changed +- Throw `UnparsableResponse` instead of a `TypeError` when a required timestamp cannot be parsed - AWS enhancement: Documentation updates. ## 3.5.0 diff --git a/src/Service/Kinesis/src/Result/DescribeStreamConsumerOutput.php b/src/Service/Kinesis/src/Result/DescribeStreamConsumerOutput.php index f5fcc478f..5e23a52ac 100644 --- a/src/Service/Kinesis/src/Result/DescribeStreamConsumerOutput.php +++ b/src/Service/Kinesis/src/Result/DescribeStreamConsumerOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Kinesis\Enum\ConsumerStatus; @@ -36,7 +37,7 @@ private function populateResultConsumerDescription(array $json): ConsumerDescrip 'ConsumerName' => (string) $json['ConsumerName'], 'ConsumerARN' => (string) $json['ConsumerARN'], 'ConsumerStatus' => !ConsumerStatus::exists((string) $json['ConsumerStatus']) ? ConsumerStatus::UNKNOWN_TO_SDK : (string) $json['ConsumerStatus'], - 'ConsumerCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])), + 'ConsumerCreationTimestamp' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'StreamARN' => (string) $json['StreamARN'], ]); } diff --git a/src/Service/Kinesis/src/Result/DescribeStreamOutput.php b/src/Service/Kinesis/src/Result/DescribeStreamOutput.php index c425b2a07..e7766b40a 100644 --- a/src/Service/Kinesis/src/Result/DescribeStreamOutput.php +++ b/src/Service/Kinesis/src/Result/DescribeStreamOutput.php @@ -3,6 +3,7 @@ namespace AsyncAws\Kinesis\Result; use AsyncAws\Core\Exception\InvalidArgument; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Kinesis\Enum\EncryptionType; @@ -174,7 +175,7 @@ private function populateResultStreamDescription(array $json): StreamDescription 'Shards' => $this->populateResultShardList($json['Shards']), 'HasMoreShards' => filter_var($json['HasMoreShards'], \FILTER_VALIDATE_BOOLEAN), 'RetentionPeriodHours' => (int) $json['RetentionPeriodHours'], - 'StreamCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['StreamCreationTimestamp'])), + 'StreamCreationTimestamp' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['StreamCreationTimestamp'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'EnhancedMonitoring' => $this->populateResultEnhancedMonitoringList($json['EnhancedMonitoring']), 'EncryptionType' => isset($json['EncryptionType']) ? (!EncryptionType::exists((string) $json['EncryptionType']) ? EncryptionType::UNKNOWN_TO_SDK : (string) $json['EncryptionType']) : null, 'KeyId' => isset($json['KeyId']) ? (string) $json['KeyId'] : null, diff --git a/src/Service/Kinesis/src/Result/DescribeStreamSummaryOutput.php b/src/Service/Kinesis/src/Result/DescribeStreamSummaryOutput.php index d6d74dba7..361f58958 100644 --- a/src/Service/Kinesis/src/Result/DescribeStreamSummaryOutput.php +++ b/src/Service/Kinesis/src/Result/DescribeStreamSummaryOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Kinesis\Enum\EncryptionType; @@ -84,7 +85,7 @@ private function populateResultStreamDescriptionSummary(array $json): StreamDesc 'StreamStatus' => !StreamStatus::exists((string) $json['StreamStatus']) ? StreamStatus::UNKNOWN_TO_SDK : (string) $json['StreamStatus'], 'StreamModeDetails' => empty($json['StreamModeDetails']) ? null : $this->populateResultStreamModeDetails($json['StreamModeDetails']), 'RetentionPeriodHours' => (int) $json['RetentionPeriodHours'], - 'StreamCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['StreamCreationTimestamp'])), + 'StreamCreationTimestamp' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['StreamCreationTimestamp'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'EnhancedMonitoring' => $this->populateResultEnhancedMonitoringList($json['EnhancedMonitoring']), 'EncryptionType' => isset($json['EncryptionType']) ? (!EncryptionType::exists((string) $json['EncryptionType']) ? EncryptionType::UNKNOWN_TO_SDK : (string) $json['EncryptionType']) : null, 'KeyId' => isset($json['KeyId']) ? (string) $json['KeyId'] : null, diff --git a/src/Service/Kinesis/src/Result/ListStreamConsumersOutput.php b/src/Service/Kinesis/src/Result/ListStreamConsumersOutput.php index db6ef1873..078c7864f 100644 --- a/src/Service/Kinesis/src/Result/ListStreamConsumersOutput.php +++ b/src/Service/Kinesis/src/Result/ListStreamConsumersOutput.php @@ -3,6 +3,7 @@ namespace AsyncAws\Kinesis\Result; use AsyncAws\Core\Exception\InvalidArgument; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Kinesis\Enum\ConsumerStatus; @@ -113,7 +114,7 @@ private function populateResultConsumer(array $json): Consumer 'ConsumerName' => (string) $json['ConsumerName'], 'ConsumerARN' => (string) $json['ConsumerARN'], 'ConsumerStatus' => !ConsumerStatus::exists((string) $json['ConsumerStatus']) ? ConsumerStatus::UNKNOWN_TO_SDK : (string) $json['ConsumerStatus'], - 'ConsumerCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])), + 'ConsumerCreationTimestamp' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), ]); } diff --git a/src/Service/Kinesis/src/Result/RegisterStreamConsumerOutput.php b/src/Service/Kinesis/src/Result/RegisterStreamConsumerOutput.php index ba81b6994..e9f535b50 100644 --- a/src/Service/Kinesis/src/Result/RegisterStreamConsumerOutput.php +++ b/src/Service/Kinesis/src/Result/RegisterStreamConsumerOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\Kinesis\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Kinesis\Enum\ConsumerStatus; @@ -37,7 +38,7 @@ private function populateResultConsumer(array $json): Consumer 'ConsumerName' => (string) $json['ConsumerName'], 'ConsumerARN' => (string) $json['ConsumerARN'], 'ConsumerStatus' => !ConsumerStatus::exists((string) $json['ConsumerStatus']) ? ConsumerStatus::UNKNOWN_TO_SDK : (string) $json['ConsumerStatus'], - 'ConsumerCreationTimestamp' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])), + 'ConsumerCreationTimestamp' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['ConsumerCreationTimestamp'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), ]); } } diff --git a/src/Service/S3Vectors/CHANGELOG.md b/src/Service/S3Vectors/CHANGELOG.md index 15069ee62..3d46e9479 100644 --- a/src/Service/S3Vectors/CHANGELOG.md +++ b/src/Service/S3Vectors/CHANGELOG.md @@ -2,6 +2,10 @@ ## NOT RELEASED +### Changed + +- Throw `UnparsableResponse` instead of a `TypeError` when a required timestamp cannot be parsed + ## 2.1.0 ### Added diff --git a/src/Service/S3Vectors/src/Result/GetIndexOutput.php b/src/Service/S3Vectors/src/Result/GetIndexOutput.php index 30eef7eac..865e1c283 100644 --- a/src/Service/S3Vectors/src/Result/GetIndexOutput.php +++ b/src/Service/S3Vectors/src/Result/GetIndexOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\S3Vectors\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\S3Vectors\Enum\DataType; @@ -48,7 +49,7 @@ private function populateResultIndex(array $json): Index 'vectorBucketName' => (string) $json['vectorBucketName'], 'indexName' => (string) $json['indexName'], 'indexArn' => (string) $json['indexArn'], - 'creationTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])), + 'creationTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'dataType' => !DataType::exists((string) $json['dataType']) ? DataType::UNKNOWN_TO_SDK : (string) $json['dataType'], 'dimension' => (int) $json['dimension'], 'distanceMetric' => !DistanceMetric::exists((string) $json['distanceMetric']) ? DistanceMetric::UNKNOWN_TO_SDK : (string) $json['distanceMetric'], diff --git a/src/Service/S3Vectors/src/Result/GetVectorBucketOutput.php b/src/Service/S3Vectors/src/Result/GetVectorBucketOutput.php index cdbd17fd3..e4ab2e621 100644 --- a/src/Service/S3Vectors/src/Result/GetVectorBucketOutput.php +++ b/src/Service/S3Vectors/src/Result/GetVectorBucketOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\S3Vectors\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\S3Vectors\Enum\SseType; @@ -44,7 +45,7 @@ private function populateResultVectorBucket(array $json): VectorBucket return new VectorBucket([ 'vectorBucketName' => (string) $json['vectorBucketName'], 'vectorBucketArn' => (string) $json['vectorBucketArn'], - 'creationTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])), + 'creationTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'encryptionConfiguration' => empty($json['encryptionConfiguration']) ? null : $this->populateResultEncryptionConfiguration($json['encryptionConfiguration']), ]); } diff --git a/src/Service/S3Vectors/src/Result/ListIndexesOutput.php b/src/Service/S3Vectors/src/Result/ListIndexesOutput.php index f81c0bcac..50ec89a42 100644 --- a/src/Service/S3Vectors/src/Result/ListIndexesOutput.php +++ b/src/Service/S3Vectors/src/Result/ListIndexesOutput.php @@ -3,6 +3,7 @@ namespace AsyncAws\S3Vectors\Result; use AsyncAws\Core\Exception\InvalidArgument; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\S3Vectors\Input\ListIndexesInput; @@ -103,7 +104,7 @@ private function populateResultIndexSummary(array $json): IndexSummary 'vectorBucketName' => (string) $json['vectorBucketName'], 'indexName' => (string) $json['indexName'], 'indexArn' => (string) $json['indexArn'], - 'creationTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])), + 'creationTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), ]); } diff --git a/src/Service/S3Vectors/src/Result/ListVectorBucketsOutput.php b/src/Service/S3Vectors/src/Result/ListVectorBucketsOutput.php index 43b13136f..7b7371418 100644 --- a/src/Service/S3Vectors/src/Result/ListVectorBucketsOutput.php +++ b/src/Service/S3Vectors/src/Result/ListVectorBucketsOutput.php @@ -3,6 +3,7 @@ namespace AsyncAws\S3Vectors\Result; use AsyncAws\Core\Exception\InvalidArgument; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\S3Vectors\Input\ListVectorBucketsInput; @@ -115,7 +116,7 @@ private function populateResultVectorBucketSummary(array $json): VectorBucketSum return new VectorBucketSummary([ 'vectorBucketName' => (string) $json['vectorBucketName'], 'vectorBucketArn' => (string) $json['vectorBucketArn'], - 'creationTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])), + 'creationTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['creationTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), ]); } } diff --git a/src/Service/Ses/CHANGELOG.md b/src/Service/Ses/CHANGELOG.md index a531bb31f..bf768587b 100644 --- a/src/Service/Ses/CHANGELOG.md +++ b/src/Service/Ses/CHANGELOG.md @@ -6,6 +6,10 @@ - AWS api-change: Amazon SES now supports per-message tracking overrides. You can use the new ConfigurationOverrides parameter in SendEmail and SendBulkEmail to enable or disable open and click tracking for individual messages without changing your account-level or configuration set settings. +### Changed + +- Throw `UnparsableResponse` instead of a `TypeError` when a required timestamp cannot be parsed + ## 1.16.0 ### Added diff --git a/src/Service/Ses/src/Result/GetSuppressedDestinationResponse.php b/src/Service/Ses/src/Result/GetSuppressedDestinationResponse.php index f8c1008ef..7ef18e1b6 100644 --- a/src/Service/Ses/src/Result/GetSuppressedDestinationResponse.php +++ b/src/Service/Ses/src/Result/GetSuppressedDestinationResponse.php @@ -2,6 +2,7 @@ namespace AsyncAws\Ses\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; use AsyncAws\Ses\Enum\SuppressionListReason; @@ -39,7 +40,7 @@ private function populateResultSuppressedDestination(array $json): SuppressedDes return new SuppressedDestination([ 'EmailAddress' => (string) $json['EmailAddress'], 'Reason' => !SuppressionListReason::exists((string) $json['Reason']) ? SuppressionListReason::UNKNOWN_TO_SDK : (string) $json['Reason'], - 'LastUpdateTime' => /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['LastUpdateTime'])), + 'LastUpdateTime' => \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $json['LastUpdateTime'])) ?: throw new UnparsableResponse('Invalid timestamp received.'), 'Attributes' => empty($json['Attributes']) ? null : $this->populateResultSuppressedDestinationAttributes($json['Attributes']), 'TenantName' => isset($json['TenantName']) ? (string) $json['TenantName'] : null, ]); diff --git a/src/Service/StepFunctions/CHANGELOG.md b/src/Service/StepFunctions/CHANGELOG.md index 55b4e4efc..e99e09763 100644 --- a/src/Service/StepFunctions/CHANGELOG.md +++ b/src/Service/StepFunctions/CHANGELOG.md @@ -2,6 +2,10 @@ ## NOT RELEASED +### Changed + +- Throw `UnparsableResponse` instead of a `TypeError` when a required timestamp cannot be parsed + ## 1.7.1 ### Changed diff --git a/src/Service/StepFunctions/src/Result/StartExecutionOutput.php b/src/Service/StepFunctions/src/Result/StartExecutionOutput.php index 568aa28c9..d208bf8c7 100644 --- a/src/Service/StepFunctions/src/Result/StartExecutionOutput.php +++ b/src/Service/StepFunctions/src/Result/StartExecutionOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\StepFunctions\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; @@ -40,6 +41,6 @@ protected function populateResult(Response $response): void $data = $response->toArray(); $this->executionArn = (string) $data['executionArn']; - $this->startDate = /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['startDate'])); + $this->startDate = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['startDate'])) ?: throw new UnparsableResponse('Invalid timestamp received.'); } } diff --git a/src/Service/StepFunctions/src/Result/StopExecutionOutput.php b/src/Service/StepFunctions/src/Result/StopExecutionOutput.php index 99fd245bc..7250fcb3c 100644 --- a/src/Service/StepFunctions/src/Result/StopExecutionOutput.php +++ b/src/Service/StepFunctions/src/Result/StopExecutionOutput.php @@ -2,6 +2,7 @@ namespace AsyncAws\StepFunctions\Result; +use AsyncAws\Core\Exception\UnparsableResponse; use AsyncAws\Core\Response; use AsyncAws\Core\Result; @@ -25,6 +26,6 @@ protected function populateResult(Response $response): void { $data = $response->toArray(); - $this->stopDate = /** @var \DateTimeImmutable $d */ $d = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['stopDate'])); + $this->stopDate = \DateTimeImmutable::createFromFormat('U.u', \sprintf('%.6F', $data['stopDate'])) ?: throw new UnparsableResponse('Invalid timestamp received.'); } }