Skip to content

Commit

Permalink
Improve readability and fix error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
seba-aln committed Jun 11, 2024
1 parent fa2b942 commit 5052f5c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/PubNub/Endpoints/Push/PushEndpoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,15 @@ public function pushType(string $pushType): static

protected function validatePushType()
{
if (!isset($this->pushType) || $this->pushType === null || strlen($this->pushType) === 0) {
throw new PubNubValidationException("Push type missing");
if (!isset($this->pushType) || empty($this->pushType)) {
throw new PubNubValidationException("Push type is missing");
}

if ($this->pushType === PNPushType::GCM) {
trigger_error("GCM is deprecated. Please use FCM instead.", E_USER_DEPRECATED);
}

if (
!in_array(
$this->pushType,
[PNPushType::APNS, PNPushType::APNS2, PNPushType::MPNS, PNPushType::GCM, PNPushType::FCM]
)
) {
if (!in_array($this->pushType, PNPushType::all())) {
throw new PubNubValidationException("Invalid push type");
}
}
Expand All @@ -81,14 +76,14 @@ protected function validatePushType()
*/
protected function validateDeviceId()
{
if (!is_string($this->deviceId) || strlen($this->deviceId) === 0) {
if (!isset($this->deviceId) || empty($this->deviceId)) {
throw new PubNubValidationException("Device ID is missing for push operation");
}
}

protected function validateTopic()
{
if (($this->pushType == PNPushType::APNS2) && (!is_string($this->topic) || strlen($this->topic) === 0)) {
if (($this->pushType == PNPushType::APNS2) && (!isset($this->topic) || empty($this->topic))) {
throw new PubNubValidationException("APNS2 topic is missing");
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/PubNub/Enums/PNPushType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ class PNPushType
public const MPNS = "mpns";
public const GCM = "gcm";
public const FCM = "fcm";

public static function all()
{
return [
self::APNS,
self::APNS2,
self::MPNS,
self::GCM,
self::FCM
];
}
}

0 comments on commit 5052f5c

Please sign in to comment.