Skip to content

Commit

Permalink
Number insight typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Sep 24, 2024
1 parent bbdf6db commit 01d544a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 47 deletions.
5 changes: 2 additions & 3 deletions src/Insights/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@

class Advanced extends Standard
{

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

public function getReachable()
public function getReachable(): mixed
{
return $this->data['reachable'];
}
Expand Down
6 changes: 1 addition & 5 deletions src/Insights/Basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
namespace Vonage\Insights;

use Vonage\Entity\Hydrator\ArrayHydrateInterface;

class Basic implements ArrayHydrateInterface
{
protected array $data = [];

/**
* @param $number
*/
public function __construct($number)
public function __construct(string $number)
{
$this->data['national_format_number'] = $number;
}
Expand Down
34 changes: 11 additions & 23 deletions src/Insights/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,98 +32,88 @@ public function getApiResource(): APIResource
}

/**
* @param $number
*
* @return Basic
* @throws ClientExceptionInterface
* @throws Exception
* @throws Request
* @throws Server
*/
public function basic($number): Basic
public function basic(string $number): Basic
{
$insightsResults = $this->makeRequest('/ni/basic/json', $number);

$basic = new Basic($insightsResults['national_format_number']);
$basic->fromArray($insightsResults);

return $basic;
}

/**
* @param $number
*
* @return StandardCnam
* @throws ClientExceptionInterface
* @throws Exception
* @throws Request
* @throws Server
*/
public function standardCNam($number): StandardCnam
public function standardCNam(string $number): StandardCnam
{
$insightsResults = $this->makeRequest('/ni/standard/json', $number, ['cnam' => 'true']);
$standard = new StandardCnam($insightsResults['national_format_number']);
$standard->fromArray($insightsResults);

return $standard;
}

/**
* @param $number
*
* @return AdvancedCnam
* @throws ClientExceptionInterface
* @throws Exception
* @throws Request
* @throws Server
*/
public function advancedCnam($number): AdvancedCnam
public function advancedCnam(string $number): AdvancedCnam
{
$insightsResults = $this->makeRequest('/ni/advanced/json', $number, ['cnam' => 'true']);
$standard = new AdvancedCnam($insightsResults['national_format_number']);
$standard->fromArray($insightsResults);

return $standard;
}

/**
* @param $number
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
*/
public function standard($number): Standard
public function standard(string $number): Standard
{
$insightsResults = $this->makeRequest('/ni/standard/json', $number);
$standard = new Standard($insightsResults['national_format_number']);
$standard->fromArray($insightsResults);

return $standard;
}

/**
* @param $number
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
*/
public function advanced($number): Advanced
public function advanced(string $number): Advanced
{
$insightsResults = $this->makeRequest('/ni/advanced/json', $number);
$advanced = new Advanced($insightsResults['national_format_number']);
$advanced->fromArray($insightsResults);

return $advanced;
}

/**
* @param $number
*
* @throws ClientExceptionInterface
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
*/
public function advancedAsync($number, string $webhook): void
public function advancedAsync(string $number, string $webhook): void
{
// This method does not have a return value as it's async. If there is no exception thrown
// We can assume that everything is fine
Expand All @@ -133,8 +123,6 @@ public function advancedAsync($number, string $webhook): void
/**
* Common code for generating a request
*
* @param $number
*
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
Expand Down
1 change: 0 additions & 1 deletion src/Insights/CnamTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

trait CnamTrait
{

public function getCallerName(): ?string
{
return $this->data['caller_name'] ?? null;
Expand Down
15 changes: 7 additions & 8 deletions src/Insights/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,37 @@

class Standard extends Basic
{

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

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

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

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

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

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

public function getRoaming()
public function getRoaming(): mixed
{
return $this->data['roaming'];
}
Expand Down
7 changes: 2 additions & 5 deletions src/Logger/LoggerAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@ interface LoggerAwareInterface
public function getLogger(): ?LoggerInterface;

/**
* @param string|int $level Level of message that we are logging
* @param int|string $level Level of message that we are logging
* @param array<mixed> $context Additional information for context
*/
public function log($level, string $message, array $context = []): void;
public function log(int|string $level, string $message, array $context = []): void;

/**
* @return self
*/
public function setLogger(LoggerInterface $logger);
}
4 changes: 2 additions & 2 deletions src/Logger/LoggerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ public function getLogger(): ?LoggerInterface
}

/**
* @param string|int $level Level of message that we are logging
* @param int|string $level Level of message that we are logging
* @param array<mixed> $context Additional information for context
*/
public function log($level, string $message, array $context = []): void
public function log(int|string $level, string $message, array $context = []): void
{
$logger = $this->getLogger();
if ($logger) {
Expand Down

0 comments on commit 01d544a

Please sign in to comment.