@@ -15,13 +15,15 @@ public function __construct(
15
15
}
16
16
17
17
/**
18
- * @return \Generator<\Spameri\Elastic\Entity\AbstractElasticEntity>
18
+ * @template T
19
+ * @param class-string<T> $class
20
+ * @return T
19
21
*/
20
22
public function create (
21
23
\Spameri \ElasticQuery \Response \Result \Hit $ hit ,
22
24
string |null $ class ,
23
25
\Spameri \Elastic \EntityManager |null $ entityManager ,
24
- ): \Generator
26
+ ): \Spameri \ Elastic \ Entity \ AbstractElasticEntity
25
27
{
26
28
if ($ class === null ) {
27
29
throw new \InvalidArgumentException ('Class must be set ' );
@@ -40,7 +42,7 @@ class: $class,
40
42
id: $ hit ->id (),
41
43
);
42
44
if ($ entity !== null ) {
43
- yield $ entity ;
45
+ return $ entity ;
44
46
}
45
47
46
48
$ properties = $ this ->resolveProperties (
@@ -57,7 +59,7 @@ class: $class,
57
59
58
60
$ this ->identityMap ->add ($ entity );
59
61
60
- yield $ entity ;
62
+ return $ entity ;
61
63
}
62
64
63
65
protected function resolveProperties (
@@ -86,6 +88,7 @@ protected function resolveProperties(
86
88
$ propertyTypeName = $ reflectionPropertyType ->getName ();
87
89
if ($ reflectionPropertyType ->allowsNull () && $ value === null ) {
88
90
$ propertyValue = null ;
91
+ $ setNull = true ;
89
92
90
93
} elseif ($ property ->hasDefaultValue () === true && $ value === null ) {
91
94
$ propertyValue = $ property ->getDefaultValue ();
@@ -207,11 +210,13 @@ class: $propertyTypeName,
207
210
$ propertyValue = $ value ;
208
211
}
209
212
210
- if (isset ($ propertyValue )) {
213
+ if (
214
+ isset ($ propertyValue ) || isset ($ setNull )
215
+ ) {
211
216
$ resolvedProperties [$ property ->getName ()] = $ propertyValue ;
212
217
}
213
218
214
- unset($ propertyValue );
219
+ unset($ propertyValue, $ setNull );
215
220
}
216
221
217
222
return $ resolvedProperties ;
0 commit comments