Skip to content

Commit

Permalink
Typing WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Jul 2, 2024
1 parent 8ce0b8e commit 0110fd7
Show file tree
Hide file tree
Showing 27 changed files with 277 additions and 273 deletions.
2 changes: 1 addition & 1 deletion src/PubNub/Endpoints/FileSharing/PublishFileMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function buildPath()

public function encryptMessage($message)
{
$crypto = $this->pubnub->getCryptoSafe();
$crypto = $this->pubnub->getCrypto();
$messageString = PubNubUtil::writeValueAsString($message);
if ($crypto) {
return $crypto->encrypt($messageString);
Expand Down
2 changes: 1 addition & 1 deletion src/PubNub/Endpoints/FileSharing/SendFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ protected function buildPath()

protected function encryptPayload()
{
$crypto = $this->pubnub->getCryptoSafe();
$crypto = $this->pubnub->getCrypto();
if ($this->fileHandle) {
$fileContent = stream_get_contents($this->fileHandle);
} else {
Expand Down
22 changes: 11 additions & 11 deletions src/PubNub/Endpoints/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,22 @@
use PubNub\Models\Consumer\History\PNHistoryResult;
use PubNub\PubNubUtil;


class History extends Endpoint
{
const PATH = "/v2/history/sub-key/%s/channel/%s";
const MAX_COUNT = 100;
protected const PATH = "/v2/history/sub-key/%s/channel/%s";
protected const MAX_COUNT = 100;

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

/** @var int */
protected $start;
protected ?int $start;

/** @var int */
protected $end;
protected ?int $end;

/** @var bool */
protected $reverse;
protected bool $reverse = false;

/** @var int */
protected $count;
Expand Down Expand Up @@ -156,15 +155,16 @@ protected function buildData()
protected function buildPath()
{
return sprintf(
static::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(),
static::PATH,
$this->pubnub->getConfiguration()->getSubscribeKey(),
PubNubUtil::urlEncode($this->channel)
);
}

/**
* @return PNHistoryResult
*/
public function sync()
public function sync(): PNHistoryResult
{
return parent::sync();
}
Expand All @@ -173,7 +173,7 @@ public function sync()
* @param array $result Decoded json
* @return PNHistoryResult
*/
protected function createResponse($result)
protected function createResponse($result): PNHistoryResult
{
try {
return PNHistoryResult::fromJson(
Expand Down Expand Up @@ -239,4 +239,4 @@ public function getName()
{
return "History";
}
}
}
11 changes: 6 additions & 5 deletions src/PubNub/Endpoints/HistoryDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class HistoryDelete extends Endpoint
{
const PATH = "/v3/history/sub-key/%s/channel/%s";
protected const PATH = "/v3/history/sub-key/%s/channel/%s";

/** @var string */
protected $channel;
Expand Down Expand Up @@ -70,7 +70,7 @@ protected function validateParams()
* @param array $result Decoded json
* @return mixed
*/
protected function createResponse($result)
protected function createResponse($result): PNHistoryDeleteResult
{
return new PNHistoryDeleteResult();
}
Expand Down Expand Up @@ -105,7 +105,8 @@ protected function buildData()
protected function buildPath()
{
return sprintf(
static::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(),
static::PATH,
$this->pubnub->getConfiguration()->getSubscribeKey(),
PubNubUtil::urlEncode($this->channel)
);
}
Expand Down Expand Up @@ -164,8 +165,8 @@ protected function getName()
* @return PNHistoryDeleteResult
* @throws \PubNub\Exceptions\PubNubException
*/
public function sync()
public function sync(): PNHistoryDeleteResult
{
return parent::sync();
}
}
}
12 changes: 6 additions & 6 deletions src/PubNub/Endpoints/MessageCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class MessageCount extends Endpoint
{
const PATH = "/v3/history/sub-key/%s/message-counts/%s";
protected const PATH = "/v3/history/sub-key/%s/message-counts/%s";

/** @var array */
protected $channels = [];
Expand Down Expand Up @@ -59,15 +59,14 @@ protected function validateParams()
if (count($this->channelsTimetoken) > 1 && count($this->channels) !== count($this->channelsTimetoken)) {
throw new PubNubValidationException("The number of channels and the number of timetokens do not match");
}

}

/**
* @param array $result Decoded json
* @return PNMessageCountResult
* @throws PubNubServerException
*/
protected function createResponse($result)
protected function createResponse($result): PNMessageCountResult
{
if (!isset($result['channels'])) {
$exception = (new PubNubServerException())
Expand Down Expand Up @@ -109,7 +108,8 @@ protected function buildData()
protected function buildPath()
{
return sprintf(
static::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(),
static::PATH,
$this->pubnub->getConfiguration()->getSubscribeKey(),
PubNubUtil::joinChannels($this->channels)
);
}
Expand Down Expand Up @@ -166,8 +166,8 @@ protected function getName()
* @return PNMessageCountResult
* @throws \PubNub\Exceptions\PubNubException
*/
public function sync()
public function sync(): PNMessageCountResult
{
return parent::sync();
}
}
}
49 changes: 23 additions & 26 deletions src/PubNub/Endpoints/Objects/Channel/GetAllChannelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class GetAllChannelMetadata extends ObjectsCollectionEndpoint
{
const PATH = "/v2/objects/%s/channels";
protected const PATH = "/v2/objects/%s/channels";

/** @var string */
protected $channel;
Expand Down Expand Up @@ -72,62 +72,59 @@ protected function buildPath()
* @param array $result Decoded json
* @return PNGetAllChannelMetadataResult
*/
protected function createResponse($result)
protected function createResponse($result): PNGetAllChannelMetadataResult
{
return PNGetAllChannelMetadataResult::fromPayload($result);
}

public function sync(): PNGetAllChannelMetadataResult
{
return parent::sync();
}

/**
* @return array
*/
protected function customParams()
{
$params = $this->defaultParams();

if (array_key_exists("customFields", $this->include))
{
if (array_key_exists("customFields", $this->include)) {
$params['include'] = 'custom';
}

if (array_key_exists("totalCount", $this->include))
{
if (array_key_exists("totalCount", $this->include)) {
$params['count'] = "true";
}

if (array_key_exists("next", $this->page))
{
if (array_key_exists("next", $this->page)) {
$params['start'] = $this->page["next"];
}

if (array_key_exists("prev", $this->page))
{
if (array_key_exists("prev", $this->page)) {
$params['end'] = $this->page["prev"];
}

if (!empty($this->filter))
{
if (!empty($this->filter)) {
$params['filter'] = $this->filter;
}

if (!empty($this->limit))
{
if (!empty($this->limit)) {
$params['limit'] = $this->limit;
}

if (!empty($this->sort))
{
$sortEntries = [];
if (!empty($this->sort)) {
$sortEntries = [];

foreach ($this->sort as $key => $value)
{
if ($value === 'asc' || $value === 'desc') {
array_push($sortEntries, "$key:$value");
} else {
array_push($sortEntries, $key);
foreach ($this->sort as $key => $value) {
if ($value === 'asc' || $value === 'desc') {
array_push($sortEntries, "$key:$value");
} else {
array_push($sortEntries, $key);
}
}
}

$params['sort'] = $sortEntries;
$params['sort'] = $sortEntries;
}

return $params;
Expand All @@ -138,7 +135,7 @@ protected function customParams()
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/PubNub/Endpoints/Objects/Channel/GetChannelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
use PubNub\Exceptions\PubNubValidationException;
use PubNub\Models\Consumer\Objects\Channel\PNGetChannelMetadataResult;


class GetChannelMetadata extends Endpoint
{
const PATH = "/v2/objects/%s/channels/%s";
protected const PATH = "/v2/objects/%s/channels/%s";

/** @var string */
protected $channel;
Expand Down Expand Up @@ -64,11 +63,16 @@ protected function buildPath()
* @param array $result Decoded json
* @return PNGetChannelMetadataResult
*/
protected function createResponse($result)
protected function createResponse($result): PNGetChannelMetadataResult
{
return PNGetChannelMetadataResult::fromPayload($result);
}

public function sync(): PNGetChannelMetadataResult
{
return parent::sync();
}

/**
* @return array
*/
Expand All @@ -86,7 +90,7 @@ protected function customParams()
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/PubNub/Endpoints/Objects/Channel/RemoveChannelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use PubNub\Enums\PNOperationType;
use PubNub\Exceptions\PubNubValidationException;


class RemoveChannelMetadata extends Endpoint
{
const PATH = "/v2/objects/%s/channels/%s";
protected const PATH = "/v2/objects/%s/channels/%s";

/** @var string */
protected $channel;
Expand Down Expand Up @@ -63,11 +62,16 @@ protected function buildPath()
* @param array $result Decoded json
* @return bool
*/
protected function createResponse($result)
protected function createResponse($result): bool
{
return array_key_exists("data", $result);
}

public function sync(): bool
{
return parent::sync();
}

/**
* @return array
*/
Expand All @@ -83,7 +87,7 @@ protected function customParams()
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down
12 changes: 8 additions & 4 deletions src/PubNub/Endpoints/Objects/Channel/SetChannelMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use PubNub\Models\Consumer\Objects\Channel\PNSetChannelMetadataResult;
use PubNub\PubNubUtil;


class SetChannelMetadata extends Endpoint
{
const PATH = "/v2/objects/%s/channels/%s";
protected const PATH = "/v2/objects/%s/channels/%s";

/** @var string */
protected $channel;
Expand Down Expand Up @@ -83,11 +82,16 @@ protected function buildPath()
* @param array $result Decoded json
* @return PNSetChannelMetadataResult
*/
protected function createResponse($result)
protected function createResponse($result): PNSetChannelMetadataResult
{
return PNSetChannelMetadataResult::fromPayload($result);
}

public function sync(): PNSetChannelMetadataResult
{
return parent::sync();
}

/**
* @return array
*/
Expand All @@ -105,7 +109,7 @@ protected function customParams()
*/
protected function isAuthRequired()
{
return True;
return true;
}

/**
Expand Down
Loading

0 comments on commit 0110fd7

Please sign in to comment.