Skip to content

Commit

Permalink
Merge pull request #83 from OskarStark/feature/properties-nullable
Browse files Browse the repository at this point in the history
Enhancement: Make properties nullable
  • Loading branch information
slunak authored Sep 17, 2024
2 parents 67afea9 + 935dfb6 commit 85ee422
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 38 deletions.
6 changes: 3 additions & 3 deletions src/Client/Response/CreateGroupResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ class CreateGroupResponse extends Response
/**
* Obtained group key.
*/
private string $groupKey;
private ?string $groupKey = null;

public function __construct(string $curlResponse)
{
$this->processCurlResponse($curlResponse);
}

/**
* @return string Obtained group key
* @return null|string Obtained group key or null if the request failed
*/
public function getGroupKey(): string
public function getGroupKey(): ?string
{
return $this->groupKey;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Client/Response/LicenseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ class LicenseResponse extends Response
/**
* Number of license credits remaining.
*/
private int $credits;
private ?int $credits = null;

public function __construct(string $curlResponse)
{
$this->processCurlResponse($curlResponse);
}

public function getCredits(): int
/**
* @return null|int License credits or null if the request failed
*/
public function getCredits(): ?int
{
return $this->credits;
}
Expand Down
9 changes: 6 additions & 3 deletions src/Client/Response/RetrieveGroupResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ class RetrieveGroupResponse extends Response
/**
* Name of the group.
*/
private string $name;
private ?string $name = null;

/**
* @var Recipient[] Group users
*/
private array $users;
private array $users = [];

public function __construct(string $curlResponse)
{
$this->processCurlResponse($curlResponse);
}

public function getName(): string
/**
* @return null|string Group name or null if the request failed
*/
public function getName(): ?string
{
return $this->name;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Client/Response/SubscriptionResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ class SubscriptionResponse extends Response
/**
* Applications that formerly collected Pushover user keys are encouraged to migrate to subscription keys.
*/
private string $subscribed_user_key;
private ?string $subscribed_user_key = null;

public function __construct(string $curlResponse)
{
$this->processCurlResponse($curlResponse);
}

public function getSubscribedUserKey(): string
/**
* @return null|string Subscribed user key or null if the request failed
*/
public function getSubscribedUserKey(): ?string
{
return $this->subscribed_user_key;
}
Expand Down
35 changes: 7 additions & 28 deletions src/Client/Response/UserGroupValidationResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
*/
class UserGroupValidationResponse extends Response
{
private bool $isGroup;
private ?bool $isGroup = null;

/**
* @var array<string>
*/
private array $devices;
private array $devices = [];

/**
* @var array<string>
*/
private array $licenses;
private array $licenses = [];

public function __construct(string $curlResponse)
{
Expand Down Expand Up @@ -60,41 +60,20 @@ public function getLicenses(): array
return $this->licenses;
}

private function setIsGroup(bool $isGroup): void
{
$this->isGroup = $isGroup;
}

/**
* @param array<string> $devices
*/
private function setDevices(array $devices): void
{
$this->devices = $devices;
}

/**
* @param array<string> $licenses
*/
private function setLicenses(array $licenses): void
{
$this->licenses = $licenses;
}

private function processCurlResponse(string $curlResponse): void
{
$decodedCurlResponse = $this->processInitialCurlResponse($curlResponse);

if ($this->getRequestStatus() === 1) {
$this->setDevices($decodedCurlResponse->devices);
$this->setLicenses($decodedCurlResponse->licenses);
$this->devices = $decodedCurlResponse->devices;
$this->licenses = $decodedCurlResponse->licenses;

if ($decodedCurlResponse->group === 1) {
$this->setIsGroup(true);
$this->isGroup = true;
}

if ($decodedCurlResponse->group === 0) {
$this->setIsGroup(false);
$this->isGroup = false;
}
}
}
Expand Down

0 comments on commit 85ee422

Please sign in to comment.