22
33namespace MessageBird \Objects ;
44
5+ use stdClass ;
6+
57/**
68 * Class Contact
79 *
@@ -65,16 +67,16 @@ class Contact extends Base
6567 /**
6668 * The hash of the group this contact belongs to.
6769 *
68- * @var array
70+ * @var ?stdClass
6971 */
70- protected $ groups = [] ;
72+ protected $ groups = null ;
7173
7274 /**
7375 * The hash with messages sent to contact.
7476 *
75- * @var array
77+ * @var ?stdClass
7678 */
77- protected $ messages = [] ;
79+ protected $ messages = null ;
7880
7981 /**
8082 * The date and time of the creation of the contact in RFC3339 format (Y-m-d\TH:i:sP)
@@ -100,12 +102,12 @@ public function getHref(): string
100102 return $ this ->href ;
101103 }
102104
103- public function getGroups (): array
105+ public function getGroups (): stdClass
104106 {
105107 return $ this ->groups ;
106108 }
107109
108- public function getMessages (): array
110+ public function getMessages (): stdClass
109111 {
110112 return $ this ->messages ;
111113 }
@@ -115,7 +117,7 @@ public function getCreatedDatetime(): string
115117 return $ this ->createdDatetime ;
116118 }
117119
118- public function getUpdatedDatetime (): string
120+ public function getUpdatedDatetime (): ? string
119121 {
120122 return $ this ->updatedDatetime ;
121123 }
@@ -126,16 +128,27 @@ public function getCustomDetails(): array
126128 }
127129
128130 /**
131+ * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclass()}
132+ *
129133 * @param mixed $object
130134 */
131- public function loadFromArray ($ object ): Contact
135+ public function loadFromArray ($ object ): self
132136 {
133137 unset($ this ->custom1 , $ this ->custom2 , $ this ->custom3 , $ this ->custom4 );
134-
138+
135139 return parent ::loadFromArray ($ object );
136140 }
137141
142+ public function loadFromStdclass (stdClass $ object ): self
143+ {
144+ unset($ this ->custom1 , $ this ->custom2 , $ this ->custom3 , $ this ->custom4 );
145+
146+ return parent ::loadFromStdclass ($ object );
147+ }
148+
138149 /**
150+ * @deprecated 2.2.0 No longer used by internal code, please switch to {@see self::loadFromStdclassForGroups()}
151+ *
139152 * @param mixed $object
140153 *
141154 * @return $this ->object
@@ -154,4 +167,19 @@ public function loadFromArrayForGroups($object)
154167 }
155168 return $ object ;
156169 }
170+
171+ public function loadFromStdclassForGroups (stdClass $ object )
172+ {
173+ parent ::loadFromStdclass ($ object );
174+
175+ if (!empty ($ object ->items )) {
176+ foreach ($ object ->items as &$ item ) {
177+ $ group = new Group ();
178+ $ group ->loadFromStdclass ($ item );
179+
180+ $ item = $ group ;
181+ }
182+ }
183+ return $ object ;
184+ }
157185}
0 commit comments