@@ -184,39 +184,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
184184 $ memberShape = $ member ->getShape ();
185185 switch ($ memberShape ->getType ()) {
186186 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]) ' ;
191188
192189 break ;
193190 case 'integer ' :
194191 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] ' ;
199193
200194 break ;
201195 case 'boolean ' :
202196 $ this ->requirementsRegistry ->addRequirement ('ext-filter ' );
203197
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) ' ;
208199
209200 break ;
210201 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] ' ;
215203
216204 break ;
217205 default :
218206 throw new \RuntimeException (sprintf ('Type %s is not yet implemented ' , $ memberShape ->getType ()));
219207 }
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+ ]);
220217 }
221218
222219 // This will catch arbitrary values that exists in undefined "headers"
0 commit comments