@@ -49,6 +49,19 @@ public function generate(string $className): object
49
49
return $ this ->generateObject ($ className );
50
50
}
51
51
52
+ /**
53
+ * @param class-string $className
54
+ * @param array<mixed> $config
55
+ */
56
+ public function generateWithTemporaryConfig (string $ className , array $ config ): object
57
+ {
58
+ $ this ->temporaryRegistry = $ config ;
59
+ $ object = $ this ->generateObject ($ className );
60
+ $ this ->temporaryRegistry = [];
61
+
62
+ return $ object ;
63
+ }
64
+
52
65
/**
53
66
* @param class-string $className
54
67
* @throws ReflectionException
@@ -81,23 +94,6 @@ function (ReflectionParameter $parameter) use ($className) {
81
94
: $ factoryMethod ->invokeArgs (null , $ arguments );
82
95
}
83
96
84
- private function isInRegistry (string $ key ): bool
85
- {
86
- return array_key_exists ($ key , $ this ->temporaryRegistry ) || array_key_exists ($ key , $ this ->registry );
87
- }
88
-
89
- /**
90
- * @return mixed
91
- */
92
- private function getFromRegistry (string $ key )
93
- {
94
- if (isset ($ this ->temporaryRegistry [$ key ])) {
95
- return $ this ->temporaryRegistry [$ key ]($ this , $ this ->fakerInstance );
96
- }
97
-
98
- return $ this ->registry [$ key ]($ this , $ this ->fakerInstance );
99
- }
100
-
101
97
/**
102
98
* @param ReflectionClass<object> $class
103
99
*/
@@ -171,16 +167,20 @@ function () use ($argumentName, $className, $type) {
171
167
}
172
168
}
173
169
170
+ private function isInRegistry (string $ key ): bool
171
+ {
172
+ return array_key_exists ($ key , $ this ->temporaryRegistry ) || array_key_exists ($ key , $ this ->registry );
173
+ }
174
+
174
175
/**
175
- * @param class-string $className
176
- * @param array<mixed> $config
176
+ * @return mixed
177
177
*/
178
- public function generateWithTemporaryConfig (string $ className , array $ config ): object
178
+ private function getFromRegistry (string $ key )
179
179
{
180
- $ this ->temporaryRegistry = $ config ;
181
- $ object = $ this ->generateObject ( $ className );
182
- $ this -> temporaryRegistry = [];
180
+ if ( isset ( $ this ->temporaryRegistry [ $ key ])) {
181
+ return $ this ->temporaryRegistry [ $ key ]( $ this , $ this -> fakerInstance );
182
+ }
183
183
184
- return $ object ;
184
+ return $ this -> registry [ $ key ]( $ this , $ this -> fakerInstance ) ;
185
185
}
186
186
}
0 commit comments