Skip to content

Commit 24bcc1a

Browse files
authored
Feature/typehint hardening (#506)
* Account API Typehint cleanup * Application API type hints * Credentials typehint cleaning * Entity and conversation updates * Fix tests and nullsafe properties * Number insight typehints * Fix logger phpstan baseline * Numbers API typehints * Minor added typehints * Final typehints
1 parent 6e2208a commit 24bcc1a

File tree

82 files changed

+269
-985
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+269
-985
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ parameters:
2020
count: 1
2121
path: src/Client.php
2222

23-
-
24-
message: "#^Method Vonage\\\\Client\\:\\:setLogger\\(\\) should return Vonage\\\\Logger\\\\LoggerAwareInterface but return statement is missing\\.$#"
25-
count: 1
26-
path: src/Client.php
27-
2823
-
2924
message: "#^Unsafe usage of new static\\(\\)\\.$#"
3025
count: 1

src/Account/Balance.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,20 @@
99
class Balance implements
1010
ArrayHydrateInterface
1111
{
12-
/**
13-
* @var array
14-
*/
1512
protected array $data;
1613

17-
public function __construct($balance, $autoReload)
14+
public function __construct(float $balance, bool $autoReload)
1815
{
1916
$this->data['balance'] = $balance;
2017
$this->data['auto_reload'] = $autoReload;
2118
}
2219

23-
public function getBalance()
20+
public function getBalance(): float
2421
{
2522
return $this->data['balance'];
2623
}
2724

28-
public function getAutoReload()
25+
public function getAutoReload(): bool
2926
{
3027
return $this->data['auto_reload'];
3128
}

src/Account/Client.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getAPIResource(): APIResource
3434
*
3535
* @return array<PrefixPrice>
3636
*/
37-
public function getPrefixPricing($prefix): array
37+
public function getPrefixPricing(string $prefix): array
3838
{
3939
$api = $this->getAPIResource();
4040
$api->setBaseUri('/account/get-prefix-pricing/outbound');
@@ -138,7 +138,7 @@ public function getBalance(): Balance
138138
* @throws ClientExceptionInterface
139139
* @throws ClientException\Exception
140140
*/
141-
public function topUp($trx): void
141+
public function topUp(string $trx): void
142142
{
143143
$api = $this->getAPIResource();
144144
$api->setBaseUri('/account/top-up');

src/Account/ClientFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Psr\Container\ContainerInterface;
88
use Vonage\Client\APIResource;
99
use Vonage\Client\Credentials\Handler\BasicQueryHandler;
10+
1011
class ClientFactory
1112
{
1213
public function __invoke(ContainerInterface $container): Client

src/Account/Config.php

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,14 @@ class Config implements
1414
/**
1515
* @var array<string, mixed>
1616
*/
17-
protected $data = [];
17+
protected array $data = [];
1818

19-
/**
20-
* @param string|int|null $max_outbound_request
21-
* @param string|int|null $max_inbound_request
22-
* @param string|int|null $max_calls_per_second
23-
*/
2419
public function __construct(
2520
?string $sms_callback_url = null,
2621
?string $dr_callback_url = null,
27-
$max_outbound_request = null,
28-
$max_inbound_request = null,
29-
$max_calls_per_second = null
22+
int|string $max_outbound_request = null,
23+
int|string $max_inbound_request = null,
24+
int|string $max_calls_per_second = null
3025
) {
3126
if (!is_null($sms_callback_url)) {
3227
$this->data['sms_callback_url'] = $sms_callback_url;
@@ -59,26 +54,17 @@ public function getDrCallbackUrl(): ?string
5954
return $this->data['dr_callback_url'];
6055
}
6156

62-
/**
63-
* @return string|int|null
64-
*/
65-
public function getMaxOutboundRequest()
57+
public function getMaxOutboundRequest(): int|string|null
6658
{
6759
return $this->data['max_outbound_request'];
6860
}
6961

70-
/**
71-
* @return string|int|null
72-
*/
73-
public function getMaxInboundRequest()
62+
public function getMaxInboundRequest(): int|string|null
7463
{
7564
return $this->data['max_inbound_request'];
7665
}
7766

78-
/**
79-
* @return string|int|null
80-
*/
81-
public function getMaxCallsPerSecond()
67+
public function getMaxCallsPerSecond(): int|string|null
8268
{
8369
return $this->data['max_calls_per_second'];
8470
}

src/Account/Network.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,9 @@ class Network implements
2222
use NoRequestResponseTrait;
2323
use JsonResponseTrait;
2424

25-
/**
26-
* @var array
27-
*/
2825
protected array $data = [];
2926

30-
/**
31-
* @param string|int $networkCode
32-
* @param string|int $networkName
33-
*/
34-
public function __construct($networkCode, $networkName)
27+
public function __construct(int|string $networkCode, int|string $networkName)
3528
{
3629
$this->data['network_code'] = (string)$networkCode;
3730
$this->data['network_name'] = (string)$networkName;
@@ -47,12 +40,12 @@ public function getName(): string
4740
return $this->data['network_name'];
4841
}
4942

50-
public function getOutboundSmsPrice()
43+
public function getOutboundSmsPrice(): mixed
5144
{
5245
return $this->data['sms_price'] ?? $this->data['price'];
5346
}
5447

55-
public function getOutboundVoicePrice()
48+
public function getOutboundVoicePrice(): mixed
5649
{
5750
return $this->data['voice_price'] ?? $this->data['price'];
5851
}

src/Account/PrefixPrice.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
class PrefixPrice extends Price
1010
{
11-
protected $priceMethod = 'getPrefixPrice';
11+
protected string $priceMethod = 'getPrefixPrice';
1212

13-
/**
14-
* @throws ClientException
15-
*/
1613
public function getCurrency(): ?string
1714
{
1815
throw new ClientException('Currency is unavailable from this endpoint');

src/Account/Price.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,9 @@ abstract class Price implements
2323
use NoRequestResponseTrait;
2424
use JsonResponseTrait;
2525

26-
/**
27-
* @var array<string, mixed>
28-
*/
29-
protected $data = [];
26+
protected array $data = [];
3027

31-
public function getCountryCode()
28+
public function getCountryCode(): mixed
3229
{
3330
return $this->data['country_code'];
3431
}
@@ -43,12 +40,12 @@ public function getCountryName(): ?string
4340
return $this->data['country_name'];
4441
}
4542

46-
public function getDialingPrefix()
43+
public function getDialingPrefix(): mixed
4744
{
4845
return $this->data['dialing_prefix'];
4946
}
5047

51-
public function getDefaultPrice()
48+
public function getDefaultPrice(): mixed
5249
{
5350
if (isset($this->data['default_price'])) {
5451
return $this->data['default_price'];
@@ -68,7 +65,7 @@ public function getCurrency(): ?string
6865
return $this->data['currency'];
6966
}
7067

71-
public function getNetworks()
68+
public function getNetworks(): mixed
7269
{
7370
return $this->data['networks'];
7471
}

src/Account/SmsPrice.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
declare(strict_types=1);
44

55
namespace Vonage\Account;
6+
67
class SmsPrice extends Price
78
{
8-
/**
9-
* @var string
10-
*/
11-
protected $priceMethod = 'getOutboundSmsPrice';
9+
protected string $priceMethod = 'getOutboundSmsPrice';
1210
}

src/Account/VoicePrice.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
declare(strict_types=1);
44

55
namespace Vonage\Account;
6+
67
class VoicePrice extends Price
78
{
8-
/**
9-
* @var string
10-
*/
11-
protected $priceMethod = 'getOutboundVoicePrice';
9+
protected string $priceMethod = 'getOutboundVoicePrice';
1210
}

0 commit comments

Comments
 (0)