Skip to content

Commit 5e49711

Browse files
authored
Validate value object required fields in the constructor (#1488)
* Refactor the code generating object properties * Refactor the generation of array getters Optional array fields still need to consider the property as nullable even though the getter will return an empty array as AWS does not treat absent lists the same than empty lists in input. * Add validation of required parameters in value object constructors * Remove checks for missing properties for value object request bodies This is already validated in the constructor now.
1 parent 2c214c5 commit 5e49711

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/ValueObject/Record.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class Record
2222
*/
2323
public function __construct(array $input)
2424
{
25-
$this->data = $input['Data'] ?? null;
25+
$this->data = $input['Data'] ?? $this->throwException(new InvalidArgument('Missing required field "Data".'));
2626
}
2727

2828
/**
@@ -46,11 +46,17 @@ public function getData(): string
4646
public function requestBody(): array
4747
{
4848
$payload = [];
49-
if (null === $v = $this->data) {
50-
throw new InvalidArgument(sprintf('Missing parameter "Data" for "%s". The value cannot be null.', __CLASS__));
51-
}
49+
$v = $this->data;
5250
$payload['Data'] = base64_encode($v);
5351

5452
return $payload;
5553
}
54+
55+
/**
56+
* @return never
57+
*/
58+
private function throwException(\Throwable $exception)
59+
{
60+
throw $exception;
61+
}
5662
}

0 commit comments

Comments
 (0)