@@ -23,6 +23,18 @@ public function __construct($id = null)
2323 $ this ->id = $ id ?? uniqid (true );
2424 }
2525
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+
2638 public function getHashDefinition (array $ prefixes = null ): array
2739 {
2840 $ id = $ this ->getId ();
@@ -45,15 +57,7 @@ public function getHashDefinition(array $prefixes = null): array
4557 $ properties [] = 'REPLACE ' ;
4658 }
4759
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 );
5761 }
5862
5963 public function getDefinition (): array
@@ -91,14 +95,7 @@ public function getDefinition(): array
9195
9296 $ properties [] = 'FIELDS ' ;
9397
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 );
10299 }
103100
104101 public function getId (): string
0 commit comments