Skip to content

Commit

Permalink
refactored several code sections
Browse files Browse the repository at this point in the history
removed redundant code from DeviceService class
  • Loading branch information
malle-pietje committed Jul 25, 2024
1 parent b997cdc commit 9e65fda
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Client/UniFiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private function buildQuery(array $params): string
$query[] = urlencode($key) . '=' . urlencode($value);
}
}

return implode('&', $query);
}

Expand Down
25 changes: 8 additions & 17 deletions src/Service/DeviceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,15 @@ public function __construct(UniFiClient $client)
*/
public function list(array $hostIds = [], string $time = null): array
{
$query = [];
if (!empty($hostIds)) {
$query['hostIds'] = $hostIds;
}
/**
* array_filter() removes any null values from the $query array
*/
$query = array_filter([
'hostIds' => !empty($hostIds) ? $hostIds : null,
'time' => $time
]);

if ($time) {
$query['time'] = $time;
}

if (!empty($query['hostIds'])) {
$query = 'hostIds[]=' . implode('&hostIds[]=', $query['hostIds']) . (isset($query['time']) ? '&time=' . $query['time'] : '');
}

$options = [
'query' => $query
];

return $this->client->request('GET', '/ea/devices', $options);
return $this->client->request('GET', '/ea/devices', ['query' => $query]);
}

/**
Expand Down

0 comments on commit 9e65fda

Please sign in to comment.