Skip to content

Commit

Permalink
Feature/typehint hardening (#506)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SecondeJK authored Sep 25, 2024
1 parent 6e2208a commit 24bcc1a
Show file tree
Hide file tree
Showing 82 changed files with 269 additions and 985 deletions.
5 changes: 0 additions & 5 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ parameters:
count: 1
path: src/Client.php

-
message: "#^Method Vonage\\\\Client\\:\\:setLogger\\(\\) should return Vonage\\\\Logger\\\\LoggerAwareInterface but return statement is missing\\.$#"
count: 1
path: src/Client.php

-
message: "#^Unsafe usage of new static\\(\\)\\.$#"
count: 1
Expand Down
9 changes: 3 additions & 6 deletions src/Account/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,20 @@
class Balance implements
ArrayHydrateInterface
{
/**
* @var array
*/
protected array $data;

public function __construct($balance, $autoReload)
public function __construct(float $balance, bool $autoReload)
{
$this->data['balance'] = $balance;
$this->data['auto_reload'] = $autoReload;
}

public function getBalance()
public function getBalance(): float
{
return $this->data['balance'];
}

public function getAutoReload()
public function getAutoReload(): bool
{
return $this->data['auto_reload'];
}
Expand Down
4 changes: 2 additions & 2 deletions src/Account/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function getAPIResource(): APIResource
*
* @return array<PrefixPrice>
*/
public function getPrefixPricing($prefix): array
public function getPrefixPricing(string $prefix): array
{
$api = $this->getAPIResource();
$api->setBaseUri('/account/get-prefix-pricing/outbound');
Expand Down Expand Up @@ -138,7 +138,7 @@ public function getBalance(): Balance
* @throws ClientExceptionInterface
* @throws ClientException\Exception
*/
public function topUp($trx): void
public function topUp(string $trx): void
{
$api = $this->getAPIResource();
$api->setBaseUri('/account/top-up');
Expand Down
1 change: 1 addition & 0 deletions src/Account/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Psr\Container\ContainerInterface;
use Vonage\Client\APIResource;
use Vonage\Client\Credentials\Handler\BasicQueryHandler;

class ClientFactory
{
public function __invoke(ContainerInterface $container): Client
Expand Down
28 changes: 7 additions & 21 deletions src/Account/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ class Config implements
/**
* @var array<string, mixed>
*/
protected $data = [];
protected array $data = [];

/**
* @param string|int|null $max_outbound_request
* @param string|int|null $max_inbound_request
* @param string|int|null $max_calls_per_second
*/
public function __construct(
?string $sms_callback_url = null,
?string $dr_callback_url = null,
$max_outbound_request = null,
$max_inbound_request = null,
$max_calls_per_second = null
int|string $max_outbound_request = null,
int|string $max_inbound_request = null,
int|string $max_calls_per_second = null
) {
if (!is_null($sms_callback_url)) {
$this->data['sms_callback_url'] = $sms_callback_url;
Expand Down Expand Up @@ -59,26 +54,17 @@ public function getDrCallbackUrl(): ?string
return $this->data['dr_callback_url'];
}

/**
* @return string|int|null
*/
public function getMaxOutboundRequest()
public function getMaxOutboundRequest(): int|string|null
{
return $this->data['max_outbound_request'];
}

/**
* @return string|int|null
*/
public function getMaxInboundRequest()
public function getMaxInboundRequest(): int|string|null
{
return $this->data['max_inbound_request'];
}

/**
* @return string|int|null
*/
public function getMaxCallsPerSecond()
public function getMaxCallsPerSecond(): int|string|null
{
return $this->data['max_calls_per_second'];
}
Expand Down
13 changes: 3 additions & 10 deletions src/Account/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,9 @@ class Network implements
use NoRequestResponseTrait;
use JsonResponseTrait;

/**
* @var array
*/
protected array $data = [];

/**
* @param string|int $networkCode
* @param string|int $networkName
*/
public function __construct($networkCode, $networkName)
public function __construct(int|string $networkCode, int|string $networkName)
{
$this->data['network_code'] = (string)$networkCode;
$this->data['network_name'] = (string)$networkName;
Expand All @@ -47,12 +40,12 @@ public function getName(): string
return $this->data['network_name'];
}

public function getOutboundSmsPrice()
public function getOutboundSmsPrice(): mixed
{
return $this->data['sms_price'] ?? $this->data['price'];
}

public function getOutboundVoicePrice()
public function getOutboundVoicePrice(): mixed
{
return $this->data['voice_price'] ?? $this->data['price'];
}
Expand Down
5 changes: 1 addition & 4 deletions src/Account/PrefixPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@

class PrefixPrice extends Price
{
protected $priceMethod = 'getPrefixPrice';
protected string $priceMethod = 'getPrefixPrice';

/**
* @throws ClientException
*/
public function getCurrency(): ?string
{
throw new ClientException('Currency is unavailable from this endpoint');
Expand Down
13 changes: 5 additions & 8 deletions src/Account/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ abstract class Price implements
use NoRequestResponseTrait;
use JsonResponseTrait;

/**
* @var array<string, mixed>
*/
protected $data = [];
protected array $data = [];

public function getCountryCode()
public function getCountryCode(): mixed
{
return $this->data['country_code'];
}
Expand All @@ -43,12 +40,12 @@ public function getCountryName(): ?string
return $this->data['country_name'];
}

public function getDialingPrefix()
public function getDialingPrefix(): mixed
{
return $this->data['dialing_prefix'];
}

public function getDefaultPrice()
public function getDefaultPrice(): mixed
{
if (isset($this->data['default_price'])) {
return $this->data['default_price'];
Expand All @@ -68,7 +65,7 @@ public function getCurrency(): ?string
return $this->data['currency'];
}

public function getNetworks()
public function getNetworks(): mixed
{
return $this->data['networks'];
}
Expand Down
6 changes: 2 additions & 4 deletions src/Account/SmsPrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
declare(strict_types=1);

namespace Vonage\Account;

class SmsPrice extends Price
{
/**
* @var string
*/
protected $priceMethod = 'getOutboundSmsPrice';
protected string $priceMethod = 'getOutboundSmsPrice';
}
6 changes: 2 additions & 4 deletions src/Account/VoicePrice.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
declare(strict_types=1);

namespace Vonage\Account;

class VoicePrice extends Price
{
/**
* @var string
*/
protected $priceMethod = 'getOutboundVoicePrice';
protected string $priceMethod = 'getOutboundVoicePrice';
}
27 changes: 6 additions & 21 deletions src/Application/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,17 @@ class Application implements EntityInterface, JsonSerializable, ArrayHydrateInte
use Psr7Trait;
use JsonResponseTrait;

/**
* @var VoiceConfig
*/
protected $voiceConfig;
protected VoiceConfig $voiceConfig;

/**
* @var MessagesConfig
*/
protected $messagesConfig;
protected MessagesConfig $messagesConfig;

/**
* @var RtcConfig
*/
protected $rtcConfig;
protected RtcConfig $rtcConfig;

/**
* @var VbcConfig
*/
protected $vbcConfig;
protected VbcConfig $vbcConfig;

protected $name;
protected ?string $name = null;

/**
* @var array
*/
protected $keys = [];
protected array $keys = [];

public function __construct(protected ?string $id = null)
{
Expand Down
5 changes: 1 addition & 4 deletions src/Application/MessagesConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ class MessagesConfig
public const INBOUND = 'inbound_url';
public const STATUS = 'status_url';

/**
* @var array
*/
protected $webhooks = [];
protected array $webhooks = [];

public function setWebhook($type, $url, $method = null): self
{
Expand Down
5 changes: 1 addition & 4 deletions src/Application/RtcConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ class RtcConfig
{
public const EVENT = 'event_url';

/**
* @var array
*/
protected $webhooks = [];
protected array $webhooks = [];

public function setWebhook($type, $url, $method = null): self
{
Expand Down
5 changes: 1 addition & 4 deletions src/Application/VbcConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class VbcConfig
{
/**
* @var bool
*/
protected $enabled = false;
protected bool $enabled = false;

public function enable(): void
{
Expand Down
5 changes: 1 addition & 4 deletions src/Application/VoiceConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ class VoiceConfig
'apac-australia'
];

/**
* @var array
*/
protected $webhooks = [];
protected array $webhooks = [];

public function setWebhook($type, $url, $method = null): self
{
Expand Down
39 changes: 7 additions & 32 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,49 +102,24 @@ class Client implements LoggerAwareInterface
public const BASE_API = 'https://api.nexmo.com';
public const BASE_REST = 'https://rest.nexmo.com';

/**
* API Credentials
*
* @var CredentialsInterface
*/
protected $credentials;
protected CredentialsInterface $credentials;

/**
* Http Client
*
* @var HttpClient
*/
protected $client;
protected ClientInterface $client;

/**
* @var bool
*/
protected $debug = false;
protected mixed $debug = false;

/**
* @var ContainerInterface
*/
protected $factory;
protected ContainerInterface $factory;

/**
* @var LoggerInterface
*/
protected $logger;

/**
* @var array
*/
protected $options = ['show_deprecations' => false, 'debug' => false];
protected array $options = ['show_deprecations' => false, 'debug' => false];

/**
* @string
*/
public $apiUrl;
public string $apiUrl;

/**
* @string
*/
public $restUrl;
public string $restUrl;

/**
* Create a new API client using the provided credentials.
Expand Down
Loading

0 comments on commit 24bcc1a

Please sign in to comment.