@@ -184,39 +184,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
184
184
$ memberShape = $ member ->getShape ();
185
185
switch ($ memberShape ->getType ()) {
186
186
case 'timestamp ' :
187
- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null; ' . "\n" , [
188
- 'PROPERTY_NAME ' => $ propertyName ,
189
- 'LOCATION_NAME ' => $ locationName ,
190
- ]);
187
+ $ input = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0]) ' ;
191
188
192
189
break ;
193
190
case 'integer ' :
194
191
case 'long ' :
195
- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null; ' . "\n" , [
196
- 'PROPERTY_NAME ' => $ propertyName ,
197
- 'LOCATION_NAME ' => $ locationName ,
198
- ]);
192
+ $ input = '(int) $headers["LOCATION_NAME"][0] ' ;
199
193
200
194
break ;
201
195
case 'boolean ' :
202
196
$ this ->requirementsRegistry ->addRequirement ('ext-filter ' );
203
197
204
- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null; ' . "\n" , [
205
- 'PROPERTY_NAME ' => $ propertyName ,
206
- 'LOCATION_NAME ' => $ locationName ,
207
- ]);
198
+ $ input = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) ' ;
208
199
209
200
break ;
210
201
case 'string ' :
211
- $ body .= strtr ('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null; ' . "\n" , [
212
- 'PROPERTY_NAME ' => $ propertyName ,
213
- 'LOCATION_NAME ' => $ locationName ,
214
- ]);
202
+ $ input = '$headers["LOCATION_NAME"][0] ' ;
215
203
216
204
break ;
217
205
default :
218
206
throw new \RuntimeException (sprintf ('Type %s is not yet implemented ' , $ memberShape ->getType ()));
219
207
}
208
+
209
+ if (!$ member ->isRequired ()) {
210
+ $ input = 'isset($headers["LOCATION_NAME"][0]) ? ' . $ input . ' : null ' ;
211
+ }
212
+
213
+ $ body .= strtr ('$this->PROPERTY_NAME = ' . $ input . "; \n" , [
214
+ 'PROPERTY_NAME ' => $ propertyName ,
215
+ 'LOCATION_NAME ' => $ locationName ,
216
+ ]);
220
217
}
221
218
222
219
// This will catch arbitrary values that exists in undefined "headers"
0 commit comments