diff --git a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php index c9129809..081d94eb 100644 --- a/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php +++ b/src/PubNub/Endpoints/FileSharing/PublishFileMessage.php @@ -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); diff --git a/src/PubNub/Endpoints/FileSharing/SendFile.php b/src/PubNub/Endpoints/FileSharing/SendFile.php index 02ee6b43..aea86292 100644 --- a/src/PubNub/Endpoints/FileSharing/SendFile.php +++ b/src/PubNub/Endpoints/FileSharing/SendFile.php @@ -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 { diff --git a/src/PubNub/Endpoints/History.php b/src/PubNub/Endpoints/History.php index 24b0ed2e..e065e243 100644 --- a/src/PubNub/Endpoints/History.php +++ b/src/PubNub/Endpoints/History.php @@ -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; @@ -156,7 +155,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) ); } @@ -164,7 +164,7 @@ protected function buildPath() /** * @return PNHistoryResult */ - public function sync() + public function sync(): PNHistoryResult { return parent::sync(); } @@ -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( @@ -239,4 +239,4 @@ public function getName() { return "History"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/HistoryDelete.php b/src/PubNub/Endpoints/HistoryDelete.php index 66b9970c..8a82c245 100644 --- a/src/PubNub/Endpoints/HistoryDelete.php +++ b/src/PubNub/Endpoints/HistoryDelete.php @@ -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; @@ -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(); } @@ -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) ); } @@ -164,8 +165,8 @@ protected function getName() * @return PNHistoryDeleteResult * @throws \PubNub\Exceptions\PubNubException */ - public function sync() + public function sync(): PNHistoryDeleteResult { return parent::sync(); } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/MessageCount.php b/src/PubNub/Endpoints/MessageCount.php index f6b7ca08..ab0c4717 100644 --- a/src/PubNub/Endpoints/MessageCount.php +++ b/src/PubNub/Endpoints/MessageCount.php @@ -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 = []; @@ -59,7 +59,6 @@ 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"); } - } /** @@ -67,7 +66,7 @@ protected function validateParams() * @return PNMessageCountResult * @throws PubNubServerException */ - protected function createResponse($result) + protected function createResponse($result): PNMessageCountResult { if (!isset($result['channels'])) { $exception = (new PubNubServerException()) @@ -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) ); } @@ -166,8 +166,8 @@ protected function getName() * @return PNMessageCountResult * @throws \PubNub\Exceptions\PubNubException */ - public function sync() + public function sync(): PNMessageCountResult { return parent::sync(); } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Objects/Channel/GetAllChannelMetadata.php b/src/PubNub/Endpoints/Objects/Channel/GetAllChannelMetadata.php index 79be6e87..71a581b2 100644 --- a/src/PubNub/Endpoints/Objects/Channel/GetAllChannelMetadata.php +++ b/src/PubNub/Endpoints/Objects/Channel/GetAllChannelMetadata.php @@ -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; @@ -72,11 +72,16 @@ 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 */ @@ -84,50 +89,42 @@ 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; @@ -138,7 +135,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Objects/Channel/GetChannelMetadata.php b/src/PubNub/Endpoints/Objects/Channel/GetChannelMetadata.php index ad955c5a..ec3570f0 100644 --- a/src/PubNub/Endpoints/Objects/Channel/GetChannelMetadata.php +++ b/src/PubNub/Endpoints/Objects/Channel/GetChannelMetadata.php @@ -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; @@ -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 */ @@ -86,7 +90,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Objects/Channel/RemoveChannelMetadata.php b/src/PubNub/Endpoints/Objects/Channel/RemoveChannelMetadata.php index e7be49cd..21e2267e 100644 --- a/src/PubNub/Endpoints/Objects/Channel/RemoveChannelMetadata.php +++ b/src/PubNub/Endpoints/Objects/Channel/RemoveChannelMetadata.php @@ -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; @@ -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 */ @@ -83,7 +87,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Objects/Channel/SetChannelMetadata.php b/src/PubNub/Endpoints/Objects/Channel/SetChannelMetadata.php index 2ed51a9d..c275ce55 100644 --- a/src/PubNub/Endpoints/Objects/Channel/SetChannelMetadata.php +++ b/src/PubNub/Endpoints/Objects/Channel/SetChannelMetadata.php @@ -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; @@ -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 */ @@ -105,7 +109,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Objects/Member/GetMembers.php b/src/PubNub/Endpoints/Objects/Member/GetMembers.php index 0ef39e0e..923ef1f9 100644 --- a/src/PubNub/Endpoints/Objects/Member/GetMembers.php +++ b/src/PubNub/Endpoints/Objects/Member/GetMembers.php @@ -8,10 +8,9 @@ use PubNub\Exceptions\PubNubValidationException; use PubNub\Models\Consumer\Objects\Member\PNMembersResult; - class GetMembers extends ObjectsCollectionEndpoint { - const PATH = "/v2/objects/%s/channels/%s/uuids"; + protected const PATH = "/v2/objects/%s/channels/%s/uuids"; /** @var string */ protected $channel; @@ -78,11 +77,16 @@ protected function buildPath() * @param array $result Decoded json * @return PNMembersResult */ - protected function createResponse($result) + protected function createResponse($result): PNMembersResult { return PNMembersResult::fromPayload($result); } + public function sync(): PNMembersResult + { + return parent::sync(); + } + /** * @return array */ @@ -93,18 +97,15 @@ protected function customParams() if (count($this->include) > 0) { $includes = []; - if (array_key_exists("customFields", $this->include)) - { + if (array_key_exists("customFields", $this->include)) { array_push($includes, 'custom'); } - if (array_key_exists("customUUIDFields", $this->include)) - { + if (array_key_exists("customUUIDFields", $this->include)) { array_push($includes, 'uuid.custom'); } - if (array_key_exists("UUIDFields", $this->include)) - { + if (array_key_exists("UUIDFields", $this->include)) { array_push($includes, 'uuid'); } @@ -115,45 +116,38 @@ protected function customParams() } } - 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; @@ -164,7 +158,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Objects/Member/RemoveMembers.php b/src/PubNub/Endpoints/Objects/Member/RemoveMembers.php index b216847d..8fd83cfc 100644 --- a/src/PubNub/Endpoints/Objects/Member/RemoveMembers.php +++ b/src/PubNub/Endpoints/Objects/Member/RemoveMembers.php @@ -9,10 +9,9 @@ use PubNub\Models\Consumer\Objects\Member\PNMembersResult; use PubNub\PubNubUtil; - class RemoveMembers extends ObjectsCollectionEndpoint { - const PATH = "/v2/objects/%s/channels/%s/uuids"; + protected const PATH = "/v2/objects/%s/channels/%s/uuids"; /** @var string */ protected $channel; @@ -80,8 +79,7 @@ protected function buildData() { $entries = []; - foreach($this->uuids as $value) - { + foreach ($this->uuids as $value) { $entry = [ "uuid" => [ "id" => $value, @@ -112,11 +110,16 @@ protected function buildPath() * @param array $result Decoded json * @return PNMembersResult */ - protected function createResponse($result) + protected function createResponse($result): PNMembersResult { return PNMembersResult::fromPayload($result); } + public function sync(): PNMembersResult + { + return parent::sync(); + } + /** * @return array */ @@ -127,18 +130,15 @@ protected function customParams() if (count($this->include) > 0) { $includes = []; - if (array_key_exists("customFields", $this->include)) - { + if (array_key_exists("customFields", $this->include)) { array_push($includes, 'custom'); } - if (array_key_exists("customUUIDFields", $this->include)) - { + if (array_key_exists("customUUIDFields", $this->include)) { array_push($includes, 'uuid.custom'); } - if (array_key_exists("UUIDFields", $this->include)) - { + if (array_key_exists("UUIDFields", $this->include)) { array_push($includes, 'uuid'); } @@ -149,45 +149,38 @@ protected function customParams() } } - 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; @@ -198,7 +191,7 @@ protected function customParams() */ protected function isAuthRequired() { - return True; + return true; } /** diff --git a/src/PubNub/Endpoints/Presence/GetState.php b/src/PubNub/Endpoints/Presence/GetState.php index 15d69251..6f546216 100644 --- a/src/PubNub/Endpoints/Presence/GetState.php +++ b/src/PubNub/Endpoints/Presence/GetState.php @@ -9,10 +9,9 @@ use PubNub\Models\Consumer\Presence\PNGetStateResult; use PubNub\PubNubUtil; - class GetState extends Endpoint { - const PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s"; + protected const PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s"; /** @var array */ protected $channels = []; @@ -90,7 +89,7 @@ public function buildPath() /** * @return PNGetStateResult */ - public function sync() + public function sync(): PNGetStateResult { return parent::sync(); } @@ -99,7 +98,7 @@ public function sync() * @param array $result Decoded json * @return PNGetStateResult */ - public function createResponse($result) + public function createResponse($result): PNGetStateResult { if (count($this->channels) === 1 && count($this->channelGroups) === 0) { $channels = [$this->channels[0] => $result['payload']]; @@ -173,4 +172,4 @@ public function getName() { return "Grant"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Presence/HereNow.php b/src/PubNub/Endpoints/Presence/HereNow.php index d3d5f2fb..811470b2 100644 --- a/src/PubNub/Endpoints/Presence/HereNow.php +++ b/src/PubNub/Endpoints/Presence/HereNow.php @@ -9,11 +9,10 @@ use PubNub\Models\Consumer\Presence\PNHereNowResult; use PubNub\PubNubUtil; - class HereNow extends Endpoint { - const PATH = "/v2/presence/sub-key/%s/channel/%s"; - const GLOBAL_PATH = "/v2/presence/sub-key/%s"; + protected const PATH = "/v2/presence/sub-key/%s/channel/%s"; + protected const GLOBAL_PATH = "/v2/presence/sub-key/%s"; /** @var string[] */ protected $channels = []; @@ -117,7 +116,8 @@ public function buildPath() if (count($this->channels) === 0 && count($this->groups) === 0) { return sprintf(HereNow::GLOBAL_PATH, $this->pubnub->getConfiguration()->getSubscribeKey()); } else { - return sprintf(HereNow::PATH, + return sprintf( + HereNow::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(), PubNubUtil::joinChannels($this->channels) ); @@ -127,7 +127,7 @@ public function buildPath() /** * @return PNHereNowResult */ - public function sync() + public function sync(): PNHereNowResult { return parent::sync(); } @@ -136,7 +136,7 @@ public function sync() * @param array $result Decoded json * @return PNHereNowResult */ - protected function createResponse($result) + protected function createResponse($result): PNHereNowResult { return PNHereNowResult::fromJson($result, $this->channels); } @@ -188,4 +188,4 @@ protected function getName() { return "HereNow"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Presence/Leave.php b/src/PubNub/Endpoints/Presence/Leave.php index 963e5462..de4096cb 100644 --- a/src/PubNub/Endpoints/Presence/Leave.php +++ b/src/PubNub/Endpoints/Presence/Leave.php @@ -8,10 +8,9 @@ use PubNub\Exceptions\PubNubValidationException; use PubNub\PubNubUtil; - class Leave extends Endpoint { - const PATH = "/v2/presence/sub-key/%s/channel/%s/leave"; + protected const PATH = "/v2/presence/sub-key/%s/channel/%s/leave"; /** @var string[] */ protected $channels = []; @@ -83,18 +82,24 @@ protected function buildPath() return sprintf( Leave::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(), - PubNubUtil::joinChannels($this->channels)); + PubNubUtil::joinChannels($this->channels) + ); } /** * @param array $result Decoded json * @return array */ - protected function createResponse($result) + protected function createResponse($result): array { return $result; } + public function sync(): array + { + return parent::sync(); + } + /** * @return bool */ @@ -142,5 +147,4 @@ public function getName() { return "Leave"; } - } diff --git a/src/PubNub/Endpoints/Presence/SetState.php b/src/PubNub/Endpoints/Presence/SetState.php index ede0e71a..83fbb206 100644 --- a/src/PubNub/Endpoints/Presence/SetState.php +++ b/src/PubNub/Endpoints/Presence/SetState.php @@ -9,10 +9,9 @@ use PubNub\Models\Consumer\Presence\PNSetStateResult; use PubNub\PubNubUtil; - class SetState extends Endpoint { - const PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s/data"; + protected const PATH = "/v2/presence/sub-key/%s/channel/%s/uuid/%s/data"; /** @var array */ protected $state = []; @@ -121,7 +120,7 @@ public function buildParams() /** * @return PNSetStateResult */ - public function sync() + public function sync(): PNSetStateResult { return parent::sync(); } @@ -130,7 +129,7 @@ public function sync() * @param array $result Decoded json * @return PNSetStateResult|array */ - public function createResponse($result) + public function createResponse($result): PNSetStateResult { if (array_key_exists('status', $result) && $result['status'] === 200) { return new PNSetStateResult($result['payload']); @@ -203,4 +202,4 @@ protected function getName() { return "SetState"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/Presence/WhereNow.php b/src/PubNub/Endpoints/Presence/WhereNow.php index d1d2a51b..3d36dd39 100644 --- a/src/PubNub/Endpoints/Presence/WhereNow.php +++ b/src/PubNub/Endpoints/Presence/WhereNow.php @@ -10,10 +10,9 @@ use PubNub\PubNub; use PubNub\PubNubUtil; - class WhereNow extends Endpoint { - const PATH = "/v2/presence/sub-key/%s/uuid/%s"; + protected const PATH = "/v2/presence/sub-key/%s/uuid/%s"; /** @var string */ protected $uuid; @@ -72,7 +71,8 @@ protected function buildData() */ public function buildPath() { - return sprintf(WhereNow::PATH, + return sprintf( + WhereNow::PATH, $this->pubnub->getConfiguration()->getSubscribeKey(), PubNubUtil::urlEncode($this->uuid) ); @@ -81,7 +81,7 @@ public function buildPath() /** * @return PNWhereNowResult */ - public function sync() + public function sync(): PNWhereNowResult { return parent::sync(); } @@ -90,7 +90,7 @@ public function sync() * @param array $result Decoded json * @return PNWhereNowResult */ - protected function createResponse($result) + protected function createResponse($result): PNWhereNowResult { return PNWhereNowResult::fromPayload(static::fetchPayload($result)); } @@ -142,4 +142,4 @@ protected function getName() { return "WhereNow"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Endpoints/PubSub/Fire.php b/src/PubNub/Endpoints/PubSub/Fire.php index 3d5e3685..f5ee10f2 100644 --- a/src/PubNub/Endpoints/PubSub/Fire.php +++ b/src/PubNub/Endpoints/PubSub/Fire.php @@ -155,7 +155,7 @@ protected function customParams() /** * @return PNPublishResult */ - public function sync() + public function sync(): PNPublishResult { return parent::sync(); } @@ -164,7 +164,7 @@ public function sync() * @param array $json Decoded json * @return PNPublishResult */ - protected function createResponse($json) + protected function createResponse($json): PNPublishResult { $timetoken = floatval($json[2]); diff --git a/src/PubNub/Endpoints/PubSub/Publish.php b/src/PubNub/Endpoints/PubSub/Publish.php index 202f4d89..f2aa10bd 100755 --- a/src/PubNub/Endpoints/PubSub/Publish.php +++ b/src/PubNub/Endpoints/PubSub/Publish.php @@ -10,20 +10,19 @@ use PubNub\Models\Consumer\PNPublishResult; use PubNub\PubNubUtil; - -class Publish extends Endpoint +final class Publish extends Endpoint { - const GET_PATH = "/publish/%s/%s/0/%s/%s/%s"; - const POST_PATH = "/publish/%s/%s/0/%s/%s"; + private const GET_PATH = "/publish/%s/%s/0/%s/%s/%s"; + private const POST_PATH = "/publish/%s/%s/0/%s/%s"; /** @var mixed $message to publish */ - protected $message; + protected mixed $message; - /** @var string $channel to send message on*/ - protected $channel; + /** @var string $channel to send message to */ + protected string $channel; /** @var bool $shouldStore in history */ - protected $shouldStore; + protected ?bool $shouldStore; /** @var bool $usePost HTTP method instead of default GET */ protected $usePost; @@ -249,7 +248,7 @@ protected function buildPath() /** * @return PNPublishResult */ - public function sync() + public function sync(): PNPublishResult { return parent::sync(); } @@ -258,7 +257,7 @@ public function sync() * @param array $result Decoded json * @return PNPublishResult */ - protected function createResponse($result) + protected function createResponse($result): PNPublishResult { $timetoken = floatval($result[2]); diff --git a/src/PubNub/Endpoints/PubSub/Signal.php b/src/PubNub/Endpoints/PubSub/Signal.php index bc25e253..e179e586 100644 --- a/src/PubNub/Endpoints/PubSub/Signal.php +++ b/src/PubNub/Endpoints/PubSub/Signal.php @@ -12,7 +12,7 @@ class Signal extends Endpoint { - const SIGNAL_PATH = "/signal/%s/%s/0/%s/0/%s"; + protected const SIGNAL_PATH = "/signal/%s/%s/0/%s/0/%s"; /** @var mixed $message to send the signal */ protected $message; @@ -68,11 +68,11 @@ protected function buildPath() $stringifiedMessage = PubNubUtil::urlEncode(PubNubUtil::writeValueAsString($this->message)); return sprintf( - static::SIGNAL_PATH, - $this->pubnub->getConfiguration()->getPublishKey(), - $this->pubnub->getConfiguration()->getSubscribeKey(), - PubNubUtil::urlEncode($this->channel), - $stringifiedMessage + static::SIGNAL_PATH, + $this->pubnub->getConfiguration()->getPublishKey(), + $this->pubnub->getConfiguration()->getSubscribeKey(), + PubNubUtil::urlEncode($this->channel), + $stringifiedMessage ); } @@ -88,18 +88,18 @@ protected function customParams() } /** - * @return PNPublishResult + * @return PNSignalResult */ - public function sync() + public function sync(): PNSignalResult { return parent::sync(); } /** * @param array $result Decoded json - * @return PNPublishResult + * @return PNSignalResult */ - protected function createResponse($result) + protected function createResponse($result): PNSignalResult { $timetoken = floatval($result[2]); diff --git a/src/PubNub/Endpoints/PubSub/Subscribe.php b/src/PubNub/Endpoints/PubSub/Subscribe.php index 8c45176e..e4db64ca 100644 --- a/src/PubNub/Endpoints/PubSub/Subscribe.php +++ b/src/PubNub/Endpoints/PubSub/Subscribe.php @@ -173,7 +173,7 @@ public function sync() * @param array $result Decoded json * @return SubscribeEnvelope */ - protected function createResponse($result) + protected function createResponse($result): SubscribeEnvelope { return SubscribeEnvelope::fromJson($result); } diff --git a/src/PubNub/Endpoints/Push/AddChannelsToPush.php b/src/PubNub/Endpoints/Push/AddChannelsToPush.php index aeb0f47b..00625cba 100644 --- a/src/PubNub/Endpoints/Push/AddChannelsToPush.php +++ b/src/PubNub/Endpoints/Push/AddChannelsToPush.php @@ -89,8 +89,13 @@ protected function buildPath() * @param array $result Decoded json * @return PNPushAddChannelResult */ - protected function createResponse($result) + protected function createResponse($result): PNPushAddChannelResult { return new PNPushAddChannelResult(); } + + public function sync(): PNPushAddChannelResult + { + return parent::sync(); + } } diff --git a/src/PubNub/Endpoints/Push/ListPushProvisions.php b/src/PubNub/Endpoints/Push/ListPushProvisions.php index baccc9c2..e4b3ca49 100644 --- a/src/PubNub/Endpoints/Push/ListPushProvisions.php +++ b/src/PubNub/Endpoints/Push/ListPushProvisions.php @@ -63,7 +63,7 @@ protected function buildPath() * @param array $result Decoded json * @return mixed */ - protected function createResponse($result) + protected function createResponse($result): PNPushListProvisionsResult { if ($result !== null || is_array($result)) { return PNPushListProvisionsResult::fromJson($result); @@ -71,4 +71,9 @@ protected function createResponse($result) return new PNPushListProvisionsResult([]); } } + + public function sync(): PNPushListProvisionsResult + { + return parent::sync(); + } } diff --git a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php index 30e93560..15116bb7 100644 --- a/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveChannelsFromPush.php @@ -92,8 +92,13 @@ protected function buildPath() * @param array $result Decoded json * @return PNPushRemoveChannelResult */ - protected function createResponse($result) + protected function createResponse($result): PNPushRemoveChannelResult { return new PNPushRemoveChannelResult(); } + + public function sync(): PNPushRemoveChannelResult + { + return parent::sync(); + } } diff --git a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php index 2dd2632a..11f0a5da 100644 --- a/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php +++ b/src/PubNub/Endpoints/Push/RemoveDeviceFromPush.php @@ -64,8 +64,13 @@ protected function buildPath() * @param array $result Decoded json * @return PNPushRemoveAllChannelsResult */ - protected function createResponse($result) + protected function createResponse($result): PNPushRemoveAllChannelsResult { return new PNPushRemoveAllChannelsResult(); } + + public function sync(): PNPushRemoveAllChannelsResult + { + return parent::sync(); + } } diff --git a/src/PubNub/Endpoints/Time.php b/src/PubNub/Endpoints/Time.php index f7d6b135..0e58db3b 100755 --- a/src/PubNub/Endpoints/Time.php +++ b/src/PubNub/Endpoints/Time.php @@ -48,7 +48,7 @@ public function sync(): PNTimeResult * @param array $result * @return PNTimeResult */ - protected function createResponse($result) + protected function createResponse($result): PNTimeResult { $timetoken = floatval($result[0]); @@ -104,4 +104,4 @@ public function getName() { return "Time"; } -} \ No newline at end of file +} diff --git a/src/PubNub/Managers/TokenManager.php b/src/PubNub/Managers/TokenManager.php index 318a545f..84167419 100644 --- a/src/PubNub/Managers/TokenManager.php +++ b/src/PubNub/Managers/TokenManager.php @@ -4,14 +4,14 @@ class TokenManager { - private $token = null; + private ?string $token = null; - public function setToken($token) + public function setToken(string $token) { $this->token = $token; } - public function getToken() + public function getToken(): ?string { return $this->token; } diff --git a/src/PubNub/PubNub.php b/src/PubNub/PubNub.php index dbdae698..33a42ee1 100644 --- a/src/PubNub/PubNub.php +++ b/src/PubNub/PubNub.php @@ -53,6 +53,7 @@ use Psr\Log\LoggerAwareInterface; use Psr\Log\NullLogger; use PubNub\Endpoints\FileSharing\{SendFile, DeleteFile, DownloadFile, GetFileDownloadUrl, ListFiles}; +use PubNub\Models\Consumer\AccessManager\PNAccessManagerTokenResult; class PubNub implements LoggerAwareInterface { @@ -61,40 +62,33 @@ class PubNub implements LoggerAwareInterface public static $MAX_SEQUENCE = 65535; - /** @var PNConfiguration */ protected PNConfiguration $configuration; - /** @var BasePathManager */ - protected $basePathManager; + protected BasePathManager $basePathManager; - /** @var SubscriptionManager */ - protected $subscriptionManager; + protected SubscriptionManager $subscriptionManager; - /** @var TelemetryManager */ - protected $telemetryManager; + protected TelemetryManager $telemetryManager; - /** @var TokenManager */ - protected $tokenManager; + protected TokenManager $tokenManager; - /** @var LoggerInterface */ protected LoggerInterface $logger; - /** @var int $nextSequence */ - protected $nextSequence = 0; + protected int $nextSequence = 0; protected ?CryptoModule $cryptoModule = null; /** * PNConfiguration constructor. * - * @param $initialConfig PNConfiguration + * @param $config PNConfiguration */ - public function __construct($initialConfig) + public function __construct(PNConfiguration $config) { - $this->validateConfig($initialConfig); - $initialConfig->lock(); - $this->configuration = $initialConfig; - $this->basePathManager = new BasePathManager($initialConfig); + $this->validateConfig($config); + $config->lock(); + $this->configuration = $config; + $this->basePathManager = new BasePathManager($config); $this->subscriptionManager = new SubscriptionManager($this); $this->telemetryManager = new TelemetryManager(); $this->tokenManager = new TokenManager(); @@ -105,7 +99,7 @@ public function __construct($initialConfig) * Pre-configured PubNub client with demo-keys * @return static */ - public static function demo() + public static function demo(): static { return new PubNub(PNConfiguration::demoKeys()); } @@ -115,7 +109,7 @@ public static function demo() * * @throws PubNubConfigurationException */ - private function validateConfig(PNConfiguration $configuration) + private function validateConfig(PNConfiguration $configuration): void { if (empty($configuration->getUuid())) { throw new PubNubConfigurationException('UUID should not be empty'); @@ -125,7 +119,7 @@ private function validateConfig(PNConfiguration $configuration) /** * @param SubscribeCallback $listener */ - public function addListener($listener) + public function addListener(SubscribeCallback $listener): void { $this->subscriptionManager->addListener($listener); } @@ -133,7 +127,7 @@ public function addListener($listener) /** * @param SubscribeCallback $listener */ - public function removeListener($listener) + public function removeListener(SubscribeCallback $listener): void { $this->subscriptionManager->removeListener($listener); } @@ -141,7 +135,7 @@ public function removeListener($listener) /** * @return Publish */ - public function publish() + public function publish(): Publish { return new Publish($this); } @@ -149,7 +143,7 @@ public function publish() /** * @return Fire */ - public function fire() + public function fire(): Fire { return new Fire($this); } @@ -157,7 +151,7 @@ public function fire() /** * @return Signal */ - public function signal() + public function signal(): Signal { return new Signal($this); } @@ -165,7 +159,7 @@ public function signal() /** * @return SubscribeBuilder */ - public function subscribe() + public function subscribe(): SubscribeBuilder { return new SubscribeBuilder($this->subscriptionManager); } @@ -173,7 +167,7 @@ public function subscribe() /** * @return History */ - public function history() + public function history(): History { return new History($this); } @@ -181,7 +175,7 @@ public function history() /** * @return HereNow */ - public function hereNow() + public function hereNow(): HereNow { return new HereNow($this); } @@ -189,7 +183,7 @@ public function hereNow() /** * @return WhereNow */ - public function whereNow() + public function whereNow(): WhereNow { return new WhereNow($this); } @@ -197,15 +191,16 @@ public function whereNow() /** * @return Grant */ - public function grant() + public function grant(): Grant { return new Grant($this); } /** * @return PNAccessManagerTokenResult + * @throws PubNubTokenParseException */ - public function parseToken($token) + public function parseToken($token): PNAccessManagerTokenResult { return (new GrantToken($this))->parseToken($token); } @@ -213,7 +208,7 @@ public function parseToken($token) /** * @return GrantToken */ - public function grantToken() + public function grantToken(): GrantToken { return new GrantToken($this); } @@ -221,7 +216,7 @@ public function grantToken() /** * @return RevokeToken */ - public function revokeToken() + public function revokeToken(): RevokeToken { return new RevokeToken($this); } @@ -229,7 +224,7 @@ public function revokeToken() /** * @return Audit */ - public function audit() + public function audit(): Audit { return new Audit($this); } @@ -237,7 +232,7 @@ public function audit() /** * @return Revoke */ - public function revoke() + public function revoke(): Revoke { return new Revoke($this); } @@ -245,7 +240,7 @@ public function revoke() /** * @return AddChannelToChannelGroup */ - public function addChannelToChannelGroup() + public function addChannelToChannelGroup(): AddChannelToChannelGroup { return new AddChannelToChannelGroup($this); } @@ -253,7 +248,7 @@ public function addChannelToChannelGroup() /** * @return RemoveChannelFromChannelGroup */ - public function removeChannelFromChannelGroup() + public function removeChannelFromChannelGroup(): RemoveChannelFromChannelGroup { return new RemoveChannelFromChannelGroup($this); } @@ -261,7 +256,7 @@ public function removeChannelFromChannelGroup() /** * @return RemoveChannelGroup */ - public function removeChannelGroup() + public function removeChannelGroup(): RemoveChannelGroup { return new RemoveChannelGroup($this); } @@ -269,7 +264,7 @@ public function removeChannelGroup() /** * @return ListChannelsInChannelGroup */ - public function listChannelsInChannelGroup() + public function listChannelsInChannelGroup(): ListChannelsInChannelGroup { return new ListChannelsInChannelGroup($this); } @@ -285,7 +280,7 @@ public function time(): Time /** * @return AddChannelsToPush */ - public function addChannelsToPush() + public function addChannelsToPush(): AddChannelsToPush { return new AddChannelsToPush($this); } @@ -293,7 +288,7 @@ public function addChannelsToPush() /** * @return RemoveChannelsFromPush */ - public function removeChannelsFromPush() + public function removeChannelsFromPush(): RemoveChannelsFromPush { return new RemoveChannelsFromPush($this); } @@ -301,7 +296,7 @@ public function removeChannelsFromPush() /** * @return RemoveDeviceFromPush */ - public function removeAllPushChannelsForDevice() + public function removeAllPushChannelsForDevice(): RemoveDeviceFromPush { return new RemoveDeviceFromPush($this); } @@ -309,7 +304,7 @@ public function removeAllPushChannelsForDevice() /** * @return ListPushProvisions */ - public function listPushProvisions() + public function listPushProvisions(): ListPushProvisions { return new ListPushProvisions($this); } @@ -317,7 +312,7 @@ public function listPushProvisions() /** * @return SetChannelMetadata */ - public function setChannelMetadata() + public function setChannelMetadata(): SetChannelMetadata { return new SetChannelMetadata($this); } @@ -325,7 +320,7 @@ public function setChannelMetadata() /** * @return GetChannelMetadata */ - public function getChannelMetadata() + public function getChannelMetadata(): GetChannelMetadata { return new GetChannelMetadata($this); } @@ -333,7 +328,7 @@ public function getChannelMetadata() /** * @return GetAllChannelMetadata */ - public function getAllChannelMetadata() + public function getAllChannelMetadata(): GetAllChannelMetadata { return new GetAllChannelMetadata($this); } @@ -341,7 +336,7 @@ public function getAllChannelMetadata() /** * @return RemoveChannelMetadata */ - public function removeChannelMetadata() + public function removeChannelMetadata(): RemoveChannelMetadata { return new RemoveChannelMetadata($this); } @@ -349,7 +344,7 @@ public function removeChannelMetadata() /** * @return SetUUIDMetadata */ - public function setUUIDMetadata() + public function setUUIDMetadata(): SetUUIDMetadata { return new SetUUIDMetadata($this); } @@ -357,7 +352,7 @@ public function setUUIDMetadata() /** * @return GetUUIDMetadata */ - public function getUUIDMetadata() + public function getUUIDMetadata(): GetUUIDMetadata { return new GetUUIDMetadata($this); } @@ -365,7 +360,7 @@ public function getUUIDMetadata() /** * @return GetAllUUIDMetadata */ - public function getAllUUIDMetadata() + public function getAllUUIDMetadata(): GetAllUUIDMetadata { return new GetAllUUIDMetadata($this); } @@ -373,7 +368,7 @@ public function getAllUUIDMetadata() /** * @return RemoveUUIDMetadata */ - public function removeUUIDMetadata() + public function removeUUIDMetadata(): RemoveUUIDMetadata { return new RemoveUUIDMetadata($this); } @@ -381,7 +376,7 @@ public function removeUUIDMetadata() /** * @return GetMembers */ - public function getMembers() + public function getMembers(): GetMembers { return new GetMembers($this); } @@ -389,7 +384,7 @@ public function getMembers() /** * @return SetMembers */ - public function setMembers() + public function setMembers(): SetMembers { return new SetMembers($this); } @@ -397,7 +392,7 @@ public function setMembers() /** * @return RemoveMembers */ - public function removeMembers() + public function removeMembers(): RemoveMembers { return new RemoveMembers($this); } @@ -405,7 +400,7 @@ public function removeMembers() /** * @return GetMemberships */ - public function getMemberships() + public function getMemberships(): GetMemberships { return new GetMemberships($this); } @@ -413,7 +408,7 @@ public function getMemberships() /** * @return SetMemberships */ - public function setMemberships() + public function setMemberships(): SetMemberships { return new SetMemberships($this); } @@ -421,7 +416,7 @@ public function setMemberships() /** * @return RemoveMemberships */ - public function removeMemberships() + public function removeMemberships(): RemoveMemberships { return new RemoveMemberships($this); } @@ -429,7 +424,7 @@ public function removeMemberships() /** * @return int */ - public function timestamp() + public function timestamp(): int { return time(); } @@ -437,7 +432,7 @@ public function timestamp() /** * @return string */ - public static function getSdkVersion() + public static function getSdkVersion(): string { return static::SDK_VERSION; } @@ -445,7 +440,7 @@ public static function getSdkVersion() /** * @return string */ - public static function getSdkName() + public static function getSdkName(): string { return static::SDK_NAME; } @@ -453,7 +448,7 @@ public static function getSdkName() /** * @return string */ - public static function getSdkFullName() + public static function getSdkFullName(): string { $fullName = static::SDK_NAME . "/" . static::SDK_VERSION; @@ -465,7 +460,7 @@ public static function getSdkFullName() * * @return PNConfiguration */ - public function getConfiguration() + public function getConfiguration(): PNConfiguration { return $this->configuration; } @@ -473,7 +468,7 @@ public function getConfiguration() /** * @return string Base path */ - public function getBasePath($customHost = null) + public function getBasePath($customHost = null): string { return $this->basePathManager->getBasePath($customHost); } @@ -481,7 +476,7 @@ public function getBasePath($customHost = null) /** * @return Logger */ - public function getLogger() + public function getLogger(): Logger { return $this->logger; } @@ -497,7 +492,7 @@ public function setLogger(LoggerInterface $logger): void /** * @return GetState */ - public function getState() + public function getState(): GetState { return new GetState($this); } @@ -505,7 +500,7 @@ public function getState() /** * @return SetState */ - public function setState() + public function setState(): SetState { return new SetState($this); } @@ -513,7 +508,7 @@ public function setState() /** * @return HistoryDelete */ - public function deleteMessages() + public function deleteMessages(): HistoryDelete { return new HistoryDelete($this); } @@ -521,7 +516,7 @@ public function deleteMessages() /** * @return MessageCount */ - public function messageCounts() + public function messageCounts(): MessageCount { return new MessageCount($this); } @@ -529,7 +524,7 @@ public function messageCounts() /** * @return TelemetryManager */ - public function getTelemetryManager() + public function getTelemetryManager(): TelemetryManager { return $this->telemetryManager; } @@ -537,7 +532,7 @@ public function getTelemetryManager() /** * @return int unique sequence identifier */ - public function getSequenceId() + public function getSequenceId(): int { if (static::$MAX_SEQUENCE === $this->nextSequence) { $this->nextSequence = 1; @@ -551,7 +546,7 @@ public function getSequenceId() /** * @return string Token previously set by $this->setToken */ - public function getToken() + public function getToken(): ?string { return $this->tokenManager->getToken(); } @@ -559,21 +554,12 @@ public function getToken() /** * @param string $token Token obtained by GetToken */ - public function setToken($token) + public function setToken(string $token) { return $this->tokenManager->setToken($token); } - public function getCrypto(): CryptoModule | null - { - if ($this->cryptoModule) { - return $this->cryptoModule; - } else { - return $this->configuration->getCryptoSafe(); - } - } - - public function getCryptoSafe(): CryptoModule|null + public function getCrypto(): ?CryptoModule { if ($this->cryptoModule) { return $this->cryptoModule; @@ -597,27 +583,27 @@ public function fetchMessages(): FetchMessages return new FetchMessages($this); } - public function sendFile() + public function sendFile(): SendFile { return new SendFile($this); } - public function deleteFile() + public function deleteFile(): DeleteFile { return new DeleteFile($this); } - public function downloadFile() + public function downloadFile(): DownloadFile { return new DownloadFile($this); } - public function listFiles() + public function listFiles(): ListFiles { return new ListFiles($this); } - public function getFileDownloadUrl() + public function getFileDownloadUrl(): GetFileDownloadUrl { return new GetFileDownloadUrl($this); }