@@ -190,39 +190,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
190190 $ memberShape = $ member ->getShape ();
191191 switch ($ memberShape ->getType ()) {
192192 case 'timestamp ' :
193- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null; ' . "\n" , [
194- 'PROPERTY_NAME ' => $ propertyName ,
195- 'LOCATION_NAME ' => $ locationName ,
196- ]);
193+ $ input = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0]) ' ;
197194
198195 break ;
199196 case 'integer ' :
200197 case 'long ' :
201- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null; ' . "\n" , [
202- 'PROPERTY_NAME ' => $ propertyName ,
203- 'LOCATION_NAME ' => $ locationName ,
204- ]);
198+ $ input = '(int) $headers["LOCATION_NAME"][0] ' ;
205199
206200 break ;
207201 case 'boolean ' :
208202 $ this ->requirementsRegistry ->addRequirement ('ext-filter ' );
209203
210- $ body .= strtr ('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null; ' . "\n" , [
211- 'PROPERTY_NAME ' => $ propertyName ,
212- 'LOCATION_NAME ' => $ locationName ,
213- ]);
204+ $ input = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) ' ;
214205
215206 break ;
216207 case 'string ' :
217- $ body .= strtr ('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null; ' . "\n" , [
218- 'PROPERTY_NAME ' => $ propertyName ,
219- 'LOCATION_NAME ' => $ locationName ,
220- ]);
208+ $ input = '$headers["LOCATION_NAME"][0] ' ;
221209
222210 break ;
223211 default :
224212 throw new \RuntimeException (sprintf ('Type %s is not yet implemented ' , $ memberShape ->getType ()));
225213 }
214+
215+ if (!$ member ->isRequired ()) {
216+ $ input = 'isset($headers["LOCATION_NAME"][0]) ? ' . $ input . ' : null ' ;
217+ }
218+
219+ $ body .= strtr ('$this->PROPERTY_NAME = ' . $ input . "; \n" , [
220+ 'PROPERTY_NAME ' => $ propertyName ,
221+ 'LOCATION_NAME ' => $ locationName ,
222+ ]);
226223 }
227224
228225 // This will catch arbitrary values that exists in undefined "headers"
0 commit comments