Skip to content

Commit

Permalink
Numbers API typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Sep 24, 2024
1 parent e56544f commit b98e182
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 135 deletions.
6 changes: 1 addition & 5 deletions src/Network/Number/Callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
class Callback extends BaseCallback
{
protected array $expected = ['request_id', 'callback_part', 'callback_total_parts', 'number', 'status'];
protected $optional = [
protected array $optional = [
'Type' => 'number_type',
'Network' => 'carrier_network_code',
'NetworkName' => 'carrier_network_name',
Expand Down Expand Up @@ -64,10 +64,6 @@ public function getNumber()
return $this->data['number'];
}

/**
* @param $name
* @param $args
*/
public function __call($name, $args)
{
$type = substr((string) $name, 0, 3);
Expand Down
4 changes: 0 additions & 4 deletions src/Network/Number/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ class Request extends AbstractRequest implements WrapResponseInterface
*/
protected $params;

/**
* @param $number
* @param $callback
*/
public function __construct($number, $callback, array $features = [], $timeout = null, $method = null, $ref = null)
{
$this->params['number'] = $number;
Expand Down
7 changes: 2 additions & 5 deletions src/Network/Number/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

class Response extends BaseResponse
{
protected $callbacks = [];
protected array $callbacks = [];

public function __construct(array $data, array $callbacks = [])
{
Expand Down Expand Up @@ -77,10 +77,7 @@ public function getStatus()
}

/**
* @param $name
* @param $args
*
* @todo This looks somewhat illogical
* @TODO This looks somewhat illogical
*/
public function __call($name, $args)
{
Expand Down
35 changes: 7 additions & 28 deletions src/Numbers/Filter/AvailableNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,19 @@ class AvailableNumbers implements FilterInterface
'type' => 'string',
];

/**
* @var string
*/
protected $country;
protected ?string $country = null;

/**
* @var string
*/
protected $features;
protected ?string $features = null;

/**
* @var int
*/
protected $pageIndex = 1;
protected int $pageIndex = 1;

/**
* @var int
*/
protected $pageSize = 10;
protected int $pageSize = 10;

/**
* @var string
*/
protected $pattern;
protected ?string $pattern = null;

/**
* @var int
*/
protected $searchPattern = 0;
protected int $searchPattern = 0;

/**
* @var string
*/
protected $type;
protected ?string $type = null;

protected ?bool $hasApplication = null;

Expand Down
48 changes: 6 additions & 42 deletions src/Numbers/Filter/OwnedNumbers.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,35 +30,17 @@ class OwnedNumbers implements FilterInterface
'features' => 'string'
];

/**
* @var string
*/
protected $applicationId;
protected ?string $applicationId = null;

/**
* @var string
*/
protected $country;
protected ?string $country = null;

/**
* @var bool
*/
protected $hasApplication;
protected ?bool $hasApplication = null;

/**
* @var int
*/
protected $pageIndex = 1;
protected int $pageIndex = 1;

/**
* @var string
*/
protected $pattern;
protected string $pattern;

/**
* @var int
*/
protected $searchPattern = 0;
protected int $searchPattern = 0;

protected int $pageSize = 10;

Expand Down Expand Up @@ -167,9 +149,6 @@ public function getPageIndex(): int
return $this->pageIndex;
}

/**
* @return $this
*/
public function setPageIndex(int $pageIndex): self
{
$this->pageIndex = $pageIndex;
Expand All @@ -182,9 +161,6 @@ public function getPattern(): ?string
return $this->pattern;
}

/**
* @return $this
*/
public function setPattern(string $pattern): self
{
$this->pattern = $pattern;
Expand All @@ -197,9 +173,6 @@ public function getSearchPattern(): int
return $this->searchPattern;
}

/**
* @return $this
*/
public function setSearchPattern(int $searchPattern): self
{
$this->searchPattern = $searchPattern;
Expand All @@ -212,9 +185,6 @@ public function getPageSize(): int
return $this->pageSize;
}

/**
* @return $this
*/
public function setPageSize(int $pageSize): self
{
$this->pageSize = $pageSize;
Expand All @@ -227,9 +197,6 @@ public function getApplicationId(): ?string
return $this->applicationId;
}

/**
* @return $this
*/
public function setApplicationId(string $applicationId): self
{
$this->applicationId = $applicationId;
Expand All @@ -242,9 +209,6 @@ public function getHasApplication(): ?bool
return $this->hasApplication;
}

/**
* @return $this
*/
public function setHasApplication(bool $hasApplication): self
{
$this->hasApplication = $hasApplication;
Expand Down
62 changes: 11 additions & 51 deletions src/Numbers/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@
use Vonage\Entity\JsonUnserializableInterface;
use Vonage\Entity\NoRequestResponseTrait;

use function get_class;
use function in_array;
use function is_null;
use function json_decode;
use function json_last_error;
use function preg_match;
use function stripos;
use function strpos;
use function trigger_error;

class Number implements EntityInterface, JsonSerializableInterface, JsonUnserializableInterface, ArrayHydrateInterface, \Stringable
Expand Down Expand Up @@ -51,50 +49,44 @@ class Number implements EntityInterface, JsonSerializableInterface, JsonUnserial
public const ENDPOINT_VXML = 'vxml';
public const ENDPOINT_APP = 'app';

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

public function __construct($number = null, $country = null)
{
$this->data['msisdn'] = $number;
$this->data['country'] = $country;
}

public function getId()
public function getId(): mixed
{
return $this->fromData('msisdn');
}

public function getMsisdn()
public function getMsisdn(): mixed
{
return $this->getId();
}

public function getNumber()
public function getNumber(): mixed
{
return $this->getId();
}

public function getCountry()
public function getCountry(): mixed
{
return $this->fromData('country');
}

public function getType()
public function getType(): mixed
{
return $this->fromData('type');
}

public function getCost()
public function getCost(): mixed
{
return $this->fromData('cost');
}

/**
* @param $feature
*/
public function hasFeature($feature): bool
{
if (!isset($this->data['features'])) {
Expand All @@ -104,15 +96,11 @@ public function hasFeature($feature): bool
return in_array($feature, $this->data['features'], true);
}

public function getFeatures()
public function getFeatures(): mixed
{
return $this->fromData('features');
}

/**
* @param $type
* @param $url
*/
public function setWebhook($type, $url): self
{
if (!in_array($type, [self::WEBHOOK_MESSAGE, self::WEBHOOK_VOICE_STATUS], true)) {
Expand All @@ -123,26 +111,16 @@ public function setWebhook($type, $url): self
return $this;
}

/**
* @param $type
*/
public function getWebhook($type)
{
return $this->fromData($type);
}

/**
* @param $type
*/
public function hasWebhook($type): bool
{
return isset($this->data[$type]);
}

/**
* @param $endpoint
* @param $type
*/
public function setVoiceDestination($endpoint, $type = null): self
{
if (is_null($type)) {
Expand All @@ -159,9 +137,6 @@ public function setVoiceDestination($endpoint, $type = null): self
return $this;
}

/**
* @param $endpoint
*/
protected function autoType($endpoint): string
{
if ($endpoint instanceof Application) {
Expand All @@ -183,22 +158,16 @@ protected function autoType($endpoint): string
return self::ENDPOINT_TEL;
}

public function getVoiceDestination()
public function getVoiceDestination(): mixed
{
return $this->fromData('voiceCallbackValue');
}

/**
* @return mixed|null
*/
public function getVoiceType()
public function getVoiceType(): mixed
{
return $this->data['voiceCallbackType'] ?? null;
}

/**
* @param $name
*/
protected function fromData($name)
{
if (!isset($this->data[$name])) {
Expand Down Expand Up @@ -232,11 +201,8 @@ public function fromArray(array $data): void
$this->data = $data;
}

/**
* @return array|mixed
*/
#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
return $this->toArray();
}
Expand Down Expand Up @@ -264,17 +230,11 @@ public function toArray(): array
return $json;
}

/**
* @return string
*/
public function __toString(): string
{
return (string)$this->getId();
}

/**
* @return $this
*/
public function setAppId(string $appId): self
{
$this->data['messagesCallbackType'] = self::ENDPOINT_APP;
Expand Down

0 comments on commit b98e182

Please sign in to comment.