Skip to content

Commit 0b39ffd

Browse files
authored
Created Recipients object rather than it being a stdClass (#103)
1 parent 7667ed4 commit 0b39ffd

File tree

3 files changed

+125
-10
lines changed

3 files changed

+125
-10
lines changed

src/MessageBird/Objects/Message.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ class Message extends Base
127127
/**
128128
* An array of recipients
129129
*
130-
* @var array
130+
* @var Recipients
131131
*/
132-
public $recipients = array ();
132+
public $recipients;
133133

134134
/**
135135
* The URL to send status delivery reports for the message to
@@ -225,14 +225,8 @@ public function loadFromArray ($object)
225225
{
226226
parent::loadFromArray($object);
227227

228-
if (!empty($this->recipients->items)) {
229-
foreach($this->recipients->items AS &$item) {
230-
$Recipient = new Recipient();
231-
$Recipient->loadFromArray($item);
232-
233-
$item = $Recipient;
234-
}
235-
}
228+
$recipients = new Recipients();
229+
$this->recipients = $recipients->loadFromArray($this->recipients);
236230

237231
return $this;
238232
}

src/MessageBird/Objects/Recipient.php

+24
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,28 @@ class Recipient extends Base
3535
* @var string
3636
*/
3737
public $statusDatetime;
38+
39+
/**
40+
* @return int
41+
*/
42+
public function getRecipient()
43+
{
44+
return $this->recipient;
45+
}
46+
47+
/**
48+
* @return string
49+
*/
50+
public function getStatus()
51+
{
52+
return $this->status;
53+
}
54+
55+
/**
56+
* @return string
57+
*/
58+
public function getStatusDatetime()
59+
{
60+
return $this->statusDatetime;
61+
}
3862
}
+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?php
2+
3+
namespace MessageBird\Objects;
4+
5+
/**
6+
* Class Recipients
7+
*
8+
* @package MessageBird\Objects
9+
*/
10+
class Recipients extends Base
11+
{
12+
/**
13+
* @var int
14+
*/
15+
public $totalCount;
16+
17+
/**
18+
* @var int
19+
*/
20+
public $totalSentCount;
21+
22+
/**
23+
* @var int
24+
*/
25+
public $totalDeliveredCount;
26+
27+
/**
28+
* @var int
29+
*/
30+
public $totalDeliveryFailedCount;
31+
32+
/**
33+
* @var Recipient[]
34+
*/
35+
public $items;
36+
37+
/**
38+
* @return int
39+
*/
40+
public function getTotalCount()
41+
{
42+
return $this->totalCount;
43+
}
44+
45+
/**
46+
* @return int
47+
*/
48+
public function getTotalSentCount()
49+
{
50+
return $this->totalSentCount;
51+
}
52+
53+
/**
54+
* @return int
55+
*/
56+
public function getTotalDeliveredCount()
57+
{
58+
return $this->totalDeliveredCount;
59+
}
60+
61+
/**
62+
* @return int
63+
*/
64+
public function getTotalDeliveryFailedCount()
65+
{
66+
return $this->totalDeliveryFailedCount;
67+
}
68+
69+
/**
70+
* @return Recipient[]
71+
*/
72+
public function getItems()
73+
{
74+
return $this->items;
75+
}
76+
77+
/**
78+
* @param $object
79+
*
80+
* @return $this|void
81+
*/
82+
public function loadFromArray($object)
83+
{
84+
parent::loadFromArray($object);
85+
86+
if (!empty($this->items)) {
87+
foreach ($this->items as &$item) {
88+
$recipient = new Recipient();
89+
$recipient->loadFromArray($item);
90+
91+
$item = $recipient;
92+
}
93+
}
94+
95+
return $this;
96+
}
97+
}

0 commit comments

Comments
 (0)