Skip to content

Commit ab88cb8

Browse files
committed
Add return type information
1 parent e616ab1 commit ab88cb8

File tree

5 files changed

+30
-31
lines changed

5 files changed

+30
-31
lines changed

src/MessageBird/Objects/Number.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Number extends Base
4646
* Additional user-provided tags for this Number
4747
* @var array
4848
*/
49-
public $tags = array();
49+
public $tags = [];
5050

5151
/**
5252
* Number type (example: landline, mobile).

src/MessageBird/Resources/AvailablePhoneNumbers.php

+21-22
Original file line numberDiff line numberDiff line change
@@ -34,33 +34,32 @@ public function __construct(Common\HttpClient $HttpClient)
3434
* @throws \MessageBird\Exceptions\RequestException
3535
* @throws \MessageBird\Exceptions\ServerException
3636
*/
37-
public function getList($countryCode, $parameters = array())
37+
public function getList($countryCode, $parameters = []): Objects\BaseList
3838
{
3939
list($status, , $body) = $this->HttpClient->performHttpRequest(
4040
Common\HttpClient::REQUEST_GET,
4141
"available-phone-numbers/$countryCode",
4242
$parameters
4343
);
4444

45-
if ($status === 200) {
46-
$body = json_decode($body);
45+
if ($status !== 200) {
46+
return $this->processRequest($body);
47+
}
48+
$body = json_decode($body);
4749

48-
$items = $body->data;
49-
unset($body->data);
50+
$items = $body->data;
51+
unset($body->data);
5052

51-
$baseList = new Objects\BaseList();
52-
$baseList->loadFromArray($body);
53+
$baseList = new Objects\BaseList();
54+
$baseList->loadFromArray($body);
5355

54-
foreach ($items as $item) {
55-
$object = new Objects\Number($this->HttpClient);
56+
foreach ($items as $item) {
57+
$object = new Objects\Number($this->HttpClient);
5658

57-
$itemObject = $object->loadFromArray($item);
58-
$baseList->items[] = $itemObject;
59-
}
60-
return $baseList;
59+
$itemObject = $object->loadFromArray($item);
60+
$baseList->items[] = $itemObject;
6161
}
62-
63-
return $this->processRequest($body);
62+
return $baseList;
6463
}
6564

6665
/**
@@ -70,20 +69,20 @@ public function getList($countryCode, $parameters = array())
7069
* @throws \MessageBird\Exceptions\RequestException
7170
* @throws \MessageBird\Exceptions\ServerException
7271
*/
73-
private function processRequest($body)
72+
private function processRequest($body): Objects\Number
7473
{
75-
$body = @json_decode($body);
74+
$body = json_decode($body);
7675

77-
if ($body === null or $body === false) {
76+
if (json_last_error()) {
7877
throw new \MessageBird\Exceptions\ServerException('Got an invalid JSON response from the server.');
7978
}
8079

81-
if (empty($body->errors)) {
82-
return Objects\Number.loadFromArray($body->data[0]);
80+
if (!empty($body->errors)) {
81+
$ResponseError = new Common\ResponseError($body);
82+
throw new \MessageBird\Exceptions\RequestException($ResponseError->getErrorString());
8383
}
8484

85-
$ResponseError = new Common\ResponseError($body);
86-
throw new \MessageBird\Exceptions\RequestException($ResponseError->getErrorString());
85+
return Objects\Number.loadFromArray($body->data[0]);
8786
}
8887
}
8988
?>

src/MessageBird/Resources/PhoneNumbers.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ public function __construct(Common\HttpClient $HttpClient)
3232
* @param $object
3333
* @param $id
3434
*
35-
* @return $this ->Object
35+
* @return Objects\Number
3636
*
3737
* @internal param array $parameters
3838
*/
39-
public function update($object, $id)
39+
public function update($object, $id): Objects\Number
4040
{
4141
$objVars = get_object_vars($object);
4242
$body = array();

tests/integration/numbers/AvailablePhoneNumbersTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ protected function setUp(): void
77
$this->client = new \MessageBird\Client('YOUR_ACCESS_KEY', $this->mockClient);
88
}
99

10-
public function testListAvailablePhoneNumbers()
10+
public function testListAvailablePhoneNumbers(): void
1111
{
1212
$this->expectException(\MessageBird\Exceptions\ServerException::class);
1313
$this->mockClient->expects($this->once())->method('performHttpRequest')->with('GET', 'available-phone-numbers/nl', array (), null);

tests/integration/numbers/PhoneNumbersTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,21 @@ protected function setUp(): void
77
$this->client = new \MessageBird\Client('YOUR_ACCESS_KEY', $this->mockClient);
88
}
99

10-
public function testReadPhoneNumber()
10+
public function testReadPhoneNumber(): void
1111
{
1212
$this->expectException(\MessageBird\Exceptions\ServerException::class);
1313
$this->mockClient->expects($this->once())->method('performHttpRequest')->with('GET', 'phone-numbers/31612345678', null, null);
1414
$this->client->phoneNumbers->read(31612345678);
1515
}
1616

17-
public function testListPhoneNumbers()
17+
public function testListPhoneNumbers(): void
1818
{
1919
$this->expectException(\MessageBird\Exceptions\ServerException::class);
2020
$this->mockClient->expects($this->once())->method('performHttpRequest')->with('GET', 'phone-numbers', array (), null);
2121
$this->client->phoneNumbers->getList();
2222
}
2323

24-
public function testUpdatePhoneNumber()
24+
public function testUpdatePhoneNumber(): void
2525
{
2626
$Number = new \MessageBird\Objects\Number();
2727
$Number->tags = array('tag1');
@@ -31,7 +31,7 @@ public function testUpdatePhoneNumber()
3131
$this->client->phoneNumbers->update($Number, '31612345678');
3232
}
3333

34-
public function testPurchasePhoneNumber()
34+
public function testPurchasePhoneNumber(): void
3535
{
3636
$NumberPurchaseRequest = new \MessageBird\Objects\NumberPurchaseRequest();
3737
$NumberPurchaseRequest->number = '31612345678';
@@ -45,7 +45,7 @@ public function testPurchasePhoneNumber()
4545
$this->client->phoneNumbers->create($NumberPurchaseRequest);
4646
}
4747

48-
public function testCancelPhoneNumber()
48+
public function testCancelPhoneNumber(): void
4949
{
5050
$this->mockClient->expects($this->atLeastOnce())->method('performHttpRequest')->willReturn(array(204, '', ''));
5151
$this->mockClient->expects($this->once())->method('performHttpRequest')->with('DELETE', 'phone-numbers/31612345678', null, null);

0 commit comments

Comments
 (0)