Skip to content

Commit

Permalink
Entity and conversation updates
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondeJK committed Sep 24, 2024
1 parent dac3ac9 commit 130a75b
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 70 deletions.
1 change: 0 additions & 1 deletion src/Conversation/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Psr\Container\ContainerInterface;
use Vonage\Client\APIResource;
use Vonage\Client\Credentials\Handler\KeypairHandler;
use Vonage\Conversation\Client;

class ClientFactory
{
Expand Down
1 change: 0 additions & 1 deletion src/Conversation/ConversationObjects/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Vonage\Conversation\ConversationObjects;

use phpDocumentor\Reflection\Types\This;
use Vonage\Entity\Hydrator\ArrayHydrateInterface;

class Channel implements ArrayHydrateInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function setImageUrl(?string $imageUrl): CreateConversationRequest
return $this;
}

public function fromArray(array $data)
public function fromArray(array $data): void
{
if (isset($data['name'])) {
$this->setName($data['name']);
Expand Down
8 changes: 2 additions & 6 deletions src/Conversion/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use Vonage\Client\Exception as ClientException;

use function http_build_query;
use function is_null;
use function json_decode;

class Client implements ClientAwareInterface, APIClient
Expand Down Expand Up @@ -91,13 +90,10 @@ protected function sendConversion($type, $message_id, $delivered, $timestamp = n
}
}

/**
* @return ClientException\Exception|ClientException\Request|ClientException\Server
*/
protected function getException(ResponseInterface $response)
protected function getException(ResponseInterface $response): ClientException\Exception|ClientException\Request|ClientException\Server
{
$body = json_decode($response->getBody()->getContents(), true);
$status = (int)$response->getStatusCode();
$status = $response->getStatusCode();

if ($status === 402) {
$e = new ClientException\Request('This endpoint may need activating on your account. ' .
Expand Down
3 changes: 1 addition & 2 deletions src/Conversion/ClientFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
use Vonage\Client\Credentials\Handler\BasicHandler;

/**
* @todo Finish this Namespace
* @TODO Finish this Namespace
*/
class ClientFactory
{

public function __invoke(ContainerInterface $container): Client
{
/** @var APIResource $api */
Expand Down
7 changes: 2 additions & 5 deletions src/Entity/Filter/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class DateFilter implements FilterInterface
{
public const FORMAT = 'Y:m:d:H:i:s';

protected $start;
protected $end;
protected DateTime $start;
protected DateTime $end;

public function __construct(DateTime $start, DateTime $end)
{
Expand All @@ -27,9 +27,6 @@ public function __construct(DateTime $start, DateTime $end)
}
}

/**
* @return string[]
*/
public function getQuery(): array
{
return [
Expand Down
8 changes: 1 addition & 7 deletions src/Entity/Hydrator/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@

class ArrayHydrator implements HydratorInterface
{
/**
* @var ArrayHydrateInterface
*/
protected $prototype;
protected ArrayHydrateInterface $prototype;

public function hydrate(array $data): ArrayHydrateInterface
{
Expand All @@ -19,9 +16,6 @@ public function hydrate(array $data): ArrayHydrateInterface
return $object;
}

/**
* @param $object
*/
public function hydrateObject(array $data, $object)
{
$object->fromArray($data);
Expand Down
11 changes: 2 additions & 9 deletions src/Entity/Hydrator/ConstructorHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,14 @@

class ConstructorHydrator implements HydratorInterface
{
/**
* Class to create
* @var string
*/
protected $prototype;
protected string $prototype;

public function hydrate(array $data)
public function hydrate(array $data): mixed
{
$className = $this->prototype;
return new $className($data);
}

/**
* @param $object
*/
public function hydrateObject(array $data, $object): never
{
throw new \RuntimeException('Constructor Hydration can not happen on an existing object');
Expand Down
2 changes: 0 additions & 2 deletions src/Entity/Hydrator/HydratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public function hydrate(array $data);

/**
* Hydrate an existing object created outside of the hydrator
*
* @param $object
*/
public function hydrateObject(array $data, $object);
}
30 changes: 4 additions & 26 deletions src/Entity/IterableAPICollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Vonage\Client\ClientAwareInterface;
use Vonage\Client\ClientAwareTrait;
use Vonage\Client\Exception as ClientException;
use Vonage\Client\Exception\Exception;
use Vonage\Client\Exception\Server;
use Vonage\Entity\Filter\EmptyFilter;
use Vonage\Entity\Filter\FilterInterface;

Expand All @@ -26,7 +28,6 @@
use function is_null;
use function json_decode;
use function md5;
use function strpos;

/**
* Common code for iterating over a collection, and using the collection class to discover the API path.
Expand Down Expand Up @@ -402,7 +403,7 @@ public function setPage($index): self
/**
* @return int|mixed
*/
public function getPage()
public function getPage(): mixed
{
if (isset($this->pageData)) {
if (array_key_exists('page', $this->pageData)) {
Expand Down Expand Up @@ -459,11 +460,6 @@ public function getSize()
throw new RuntimeException('size not set');
}

/**
* @param $size
*
* @return $this
*/
public function setSize($size): self
{
$this->size = (int)$size;
Expand All @@ -473,8 +469,6 @@ public function setSize($size): self

/**
* Filters reduce to query params and include paging settings.
*
* @return $this
*/
public function setFilter(FilterInterface $filter): self
{
Expand All @@ -494,8 +488,6 @@ public function getFilter(): FilterInterface
/**
* Fetch a page using the current filter if no query is provided.
*
* @param $absoluteUri
*
* @throws ClientException\Exception
* @throws ClientException\Request
* @throws ClientException\Server
Expand Down Expand Up @@ -564,12 +556,7 @@ protected function fetchPage($absoluteUri): void
}
}

/**
* @throws ClientException\Exception
*
* @return ClientException\Request|ClientException\Server
*/
protected function getException(ResponseInterface $response)
protected function getException(ResponseInterface $response): ClientException\Request|ClientException\Server
{
$response->getBody()->rewind();
$body = json_decode($response->getBody()->getContents(), true);
Expand Down Expand Up @@ -599,9 +586,6 @@ public function getAutoAdvance(): bool
return $this->autoAdvance;
}

/**
* @return $this
*/
public function setAutoAdvance(bool $autoAdvance): self
{
$this->autoAdvance = $autoAdvance;
Expand All @@ -614,9 +598,6 @@ public function getNaiveCount(): bool
return $this->naiveCount;
}

/**
* @return $this
*/
public function setNaiveCount(bool $naiveCount): self
{
$this->naiveCount = $naiveCount;
Expand All @@ -643,9 +624,6 @@ public function setIndex(?int $index): IterableAPICollection
return $this;
}

/**
* @return bool
*/
public function hasPagination(): bool
{
return $this->hasPagination;
Expand Down
12 changes: 2 additions & 10 deletions src/Entity/Psr7Trait.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Vonage\Entity\Hydrator\ArrayHydrateInterface;

use function array_merge;
use function get_class;
use function is_array;
use function json_decode;
use function method_exists;
Expand All @@ -23,15 +22,8 @@
*/
trait Psr7Trait
{
/**
* @var RequestInterface
*/
protected $request;

/**
* @var ResponseInterface
*/
protected $response;
protected RequestInterface $request;
protected ResponseInterface $response;

/**
* @deprecated See error
Expand Down

0 comments on commit 130a75b

Please sign in to comment.