1919use Constructo \Support \Reflective \Notation ;
2020use Constructo \Support \Set ;
2121use Constructo \Support \Value ;
22+ use Constructo \Testing \MakeExtension ;
2223use DateTime ;
2324use Faker \Factory ;
2425use Faker \Generator ;
190191 */
191192class Faker extends Engine implements Contract
192193{
194+ use MakeExtension;
195+
193196 protected readonly Generator $ generator ;
194197
195198 /**
196199 * @param array<callable|Formatter> $formatters
197200 * @SuppressWarnings(StaticAccess)
198201 */
199202 public function __construct (
200- Notation $ case = Notation::SNAKE ,
203+ Notation $ notation = Notation::SNAKE ,
201204 array $ formatters = [],
202205 private readonly ?string $ locale = null ,
203- private readonly bool $ ignoreFromDefaultValue = false ,
206+ protected readonly bool $ ignoreFromDefaultValue = false ,
204207 ) {
205- parent ::__construct ($ case , $ formatters );
208+ parent ::__construct ($ notation , $ formatters );
206209
207210 $ this ->generator = Factory::create ($ this ->locale ($ locale ));
208211 }
@@ -245,12 +248,9 @@ public function generator(): Generator
245248 private function resolveParameters (array $ parameters , Set $ presets ): Set
246249 {
247250 $ values = [];
248- $ fromDefaultValue = $ this ->ignoreFromDefaultValue
249- ? null
250- : new FromDefaultValue ($ this ->notation , $ this ->formatters , $ this ->locale );
251251 foreach ($ parameters as $ parameter ) {
252252 $ field = $ this ->casedField ($ parameter );
253- $ generated = $ this ->generateValue ($ parameter , $ presets, $ fromDefaultValue );
253+ $ generated = $ this ->generateValue ($ parameter , $ presets );
254254
255255 if ($ generated === null ) {
256256 continue ;
@@ -274,31 +274,22 @@ private function locale(?string $locale): string
274274 /**
275275 * @throws ReflectionException
276276 */
277- private function generateValue (
278- ReflectionParameter $ parameter ,
279- Set $ presets ,
280- ?FromDefaultValue $ fromDefaultValue = null ,
281- ): ?Value {
282- return (new FromDependency (
283- $ this ->notation ,
284- $ this ->formatters ,
285- $ this ->locale ,
286- $ this ->ignoreFromDefaultValue
287- ))
288- ->then (new FromTypeDate ($ this ->notation , $ this ->formatters , $ this ->locale ))
289- ->then (new FromCollection ($ this ->notation , $ this ->formatters , $ this ->locale ))
290- ->then (new FromTypeBuiltin ($ this ->notation , $ this ->formatters , $ this ->locale ))
291- ->then (
292- new FromTypeAttributes (
293- $ this ->notation ,
294- $ this ->formatters ,
295- $ this ->locale ,
296- $ this ->ignoreFromDefaultValue
297- )
298- )
299- ->then (new FromEnum ($ this ->notation , $ this ->formatters , $ this ->locale ))
300- ->then ($ fromDefaultValue )
301- ->then (new FromPreset ($ this ->notation , $ this ->formatters , $ this ->locale ))
277+ private function generateValue (ReflectionParameter $ parameter , Set $ presets ): ?Value
278+ {
279+ $ args = [
280+ 'notation ' => $ this ->notation ,
281+ 'formatters ' => $ this ->formatters ,
282+ 'locale ' => $ this ->locale ,
283+ 'ignoreFromDefaultValue ' => $ this ->ignoreFromDefaultValue ,
284+ ];
285+ return ($ this ->make (FromDependency::class, $ args ))
286+ ->then ($ this ->make (FromTypeDate::class, $ args ))
287+ ->then ($ this ->make (FromCollection::class, $ args ))
288+ ->then ($ this ->make (FromTypeBuiltin::class, $ args ))
289+ ->then ($ this ->make (FromTypeAttributes::class, $ args ))
290+ ->then ($ this ->make (FromEnum::class, $ args ))
291+ ->then ($ this ->make (FromDefaultValue::class, $ args ))
292+ ->then ($ this ->make (FromPreset::class, $ args ))
302293 ->resolve ($ parameter , $ presets );
303294 }
304295}
0 commit comments