Skip to content

Commit

Permalink
Fix DeviceFactory stats property (#37)
Browse files Browse the repository at this point in the history
* Fix DeviceFactory stats property
- Passing a null value to an enums "tryFrom" method is deprecated
- Default "stats" property to DeviceAnalytics::OFF if "stats" is not set in data. This is the default ControlD behaviour

* Fix styling

---------

Co-authored-by: rapkis <[email protected]>
  • Loading branch information
rapkis and rapkis authored Jan 10, 2024
1 parent 03a5563 commit 1f485b4
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion src/Factories/DeviceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function make(array $data): Device
profile: (new ProfileFactory())->make($data['profile']),
profile2: ! empty($data['profile2']) ? (new ProfileFactory())->make($data['profile2']) : null,
description: $data['description'] ?? '',
stats: DeviceAnalytics::tryFrom($data['stats'] ?? null),
stats: ! empty($data['stats']) ? DeviceAnalytics::tryFrom($data['stats']) : DeviceAnalytics::OFF,
icon: $data['icon'] ?? null,
dynamicDns: $dynamicDns ?? null,
dynamicDnsExternal: $externalDns ?? null,
Expand Down
46 changes: 23 additions & 23 deletions src/Resources/Devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public function create(
string $name,
string $profilePk,
string $icon,
string $profilePk2 = null,
int $stats = null,
?string $profilePk2 = null,
?int $stats = null,
bool $legacyIpv4Status = false,
bool $learnIp = false,
bool $restricted = false,
bool $bumpTls = false,
string $description = null,
int $ddnsStatus = null,
string $ddnsSubdomain = null,
int $ddnsExternalStatus = null,
string $ddnsExternalHost = null,
?string $description = null,
?int $ddnsStatus = null,
?string $ddnsSubdomain = null,
?int $ddnsExternalStatus = null,
?string $ddnsExternalHost = null,
): Device {
$response = $this->client->post('devices', [
'name' => $name,
Expand Down Expand Up @@ -91,22 +91,22 @@ public function analyticsLevels(): array

public function modify(
string $devicePk,
string $name = null,
string $profilePk = null,
string $icon = null,
string $profilePk2 = null,
int $stats = null,
bool $legacyIpv4Status = null,
bool $learnIp = null,
bool $restricted = null,
bool $bumpTls = null,
string $description = null,
int $ddnsStatus = null,
string $ddnsSubdomain = null,
int $ddnsExternalStatus = null,
string $ddnsExternalHost = null,
DeviceStatus $status = null,
string $ctrldCustomConfig = null,
?string $name = null,
?string $profilePk = null,
?string $icon = null,
?string $profilePk2 = null,
?int $stats = null,
?bool $legacyIpv4Status = null,
?bool $learnIp = null,
?bool $restricted = null,
?bool $bumpTls = null,
?string $description = null,
?int $ddnsStatus = null,
?string $ddnsSubdomain = null,
?int $ddnsExternalStatus = null,
?string $ddnsExternalHost = null,
?DeviceStatus $status = null,
?string $ctrldCustomConfig = null,
): Device {
$response = $this->client->put("devices/{$devicePk}", [
'name' => $name,
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/MobileConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function generateProfile(
array $excludeDomain = [],
bool $dontSign = false,
bool $excludeCommon = false,
string $clientId = null,
?string $clientId = null,
): string {
return $this->client->get("mobileconfig/{$devicePk}", [
'exclude_wifi' => $excludeWifi,
Expand Down
32 changes: 16 additions & 16 deletions src/Resources/Organizations.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ public function createSubOrganization(
string $statsEndpoint,
int $maxUsers,
int $maxRouters,
string $address = null,
string $website = null,
string $contactName = null,
string $contactPhone = null,
string $parentProfile = null,
?string $address = null,
?string $website = null,
?string $contactName = null,
?string $contactPhone = null,
?string $parentProfile = null,
): Organization {
$response = $this->client->post('organizations/suborg', [
'name' => $name,
Expand All @@ -85,17 +85,17 @@ public function createSubOrganization(
}

public function modifyOrganization(
string $name = null,
string $contactEmail = null,
bool $twoFactorAuthenticationRequired = null,
string $statsEndpoint = null,
int $maxUsers = null,
int $maxRouters = null,
string $address = null,
string $website = null,
string $contactName = null,
string $contactPhone = null,
string $parentProfile = null,
?string $name = null,
?string $contactEmail = null,
?bool $twoFactorAuthenticationRequired = null,
?string $statsEndpoint = null,
?int $maxUsers = null,
?int $maxRouters = null,
?string $address = null,
?string $website = null,
?string $contactName = null,
?string $contactPhone = null,
?string $parentProfile = null,
): Organization {
$response = $this->client->put('organizations', [
'name' => $name,
Expand Down
4 changes: 2 additions & 2 deletions src/Resources/Profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function list(): ProfileList
return $result;
}

public function create(string $name, string $cloneProfileId = null): Profile
public function create(string $name, ?string $cloneProfileId = null): Profile
{
$profile = $this->client->post('profiles', [
'name' => $name,
Expand All @@ -48,7 +48,7 @@ public function create(string $name, string $cloneProfileId = null): Profile
return $this->profile->make($profile);
}

public function modify(string $profilePk, string $name = null, int $disableTtl = null): Profile
public function modify(string $profilePk, ?string $name = null, ?int $disableTtl = null): Profile
{
$profile = $this->client->post("profiles/{$profilePk}", [
'name' => $name,
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/Profiles/CustomRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct(private readonly PendingRequest $client, private rea
{
}

public function list(string $profilePk, int $folderPk = null): \Rapkis\Controld\Responses\CustomRules
public function list(string $profilePk, ?int $folderPk = null): \Rapkis\Controld\Responses\CustomRules
{
$folderPk = $folderPk ?? 'all'; // This is the default folder in ControlD that lists all rules
$response = $this->client->get("profiles/{$profilePk}/rules/{$folderPk}")->json('body.rules');
Expand Down

0 comments on commit 1f485b4

Please sign in to comment.