Skip to content

Commit 9e65fda

Browse files
committed
refactored several code sections
removed redundant code from DeviceService class
1 parent b997cdc commit 9e65fda

File tree

2 files changed

+9
-17
lines changed

2 files changed

+9
-17
lines changed

src/Client/UniFiClient.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ private function buildQuery(array $params): string
227227
$query[] = urlencode($key) . '=' . urlencode($value);
228228
}
229229
}
230+
230231
return implode('&', $query);
231232
}
232233

src/Service/DeviceService.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,24 +48,15 @@ public function __construct(UniFiClient $client)
4848
*/
4949
public function list(array $hostIds = [], string $time = null): array
5050
{
51-
$query = [];
52-
if (!empty($hostIds)) {
53-
$query['hostIds'] = $hostIds;
54-
}
51+
/**
52+
* array_filter() removes any null values from the $query array
53+
*/
54+
$query = array_filter([
55+
'hostIds' => !empty($hostIds) ? $hostIds : null,
56+
'time' => $time
57+
]);
5558

56-
if ($time) {
57-
$query['time'] = $time;
58-
}
59-
60-
if (!empty($query['hostIds'])) {
61-
$query = 'hostIds[]=' . implode('&hostIds[]=', $query['hostIds']) . (isset($query['time']) ? '&time=' . $query['time'] : '');
62-
}
63-
64-
$options = [
65-
'query' => $query
66-
];
67-
68-
return $this->client->request('GET', '/ea/devices', $options);
59+
return $this->client->request('GET', '/ea/devices', ['query' => $query]);
6960
}
7061

7162
/**

0 commit comments

Comments
 (0)