@@ -23,6 +23,18 @@ public function __construct($id = null)
23
23
$ this ->id = $ id ?? uniqid (true );
24
24
}
25
25
26
+ protected function addFieldsToProperties ($ properties ): array
27
+ {
28
+ /** @var FieldInterface $field */
29
+ foreach (get_object_vars ($ this ) as $ field ) {
30
+ if ($ field instanceof FieldInterface && !is_null ($ field ->getValue ())) {
31
+ $ properties [] = $ field ->getName ();
32
+ $ properties [] = $ field ->getValue ();
33
+ }
34
+ }
35
+ return $ properties ;
36
+ }
37
+
26
38
public function getHashDefinition (array $ prefixes = null ): array
27
39
{
28
40
$ id = $ this ->getId ();
@@ -45,15 +57,7 @@ public function getHashDefinition(array $prefixes = null): array
45
57
$ properties [] = 'REPLACE ' ;
46
58
}
47
59
48
- /** @var FieldInterface $field */
49
- foreach (get_object_vars ($ this ) as $ field ) {
50
- if ($ field instanceof FieldInterface && !is_null ($ field ->getValue ())) {
51
- $ properties [] = $ field ->getName ();
52
- $ properties [] = $ field ->getValue ();
53
- }
54
- }
55
-
56
- return $ properties ;
60
+ return $ this ->addFieldsToProperties ($ properties );
57
61
}
58
62
59
63
public function getDefinition (): array
@@ -91,14 +95,7 @@ public function getDefinition(): array
91
95
92
96
$ properties [] = 'FIELDS ' ;
93
97
94
- /** @var FieldInterface $field */
95
- foreach (get_object_vars ($ this ) as $ field ) {
96
- if ($ field instanceof FieldInterface && !is_null ($ field ->getValue ())) {
97
- $ properties [] = $ field ->getName ();
98
- $ properties [] = $ field ->getValue ();
99
- }
100
- }
101
- return $ properties ;
98
+ return $ this ->addFieldsToProperties ($ properties );
102
99
}
103
100
104
101
public function getId (): string
0 commit comments