Skip to content

Commit 2bf8f13

Browse files
committed
Cleanup
1 parent 5caf620 commit 2bf8f13

28 files changed

+113
-80
lines changed

app/controllers/HyperVAdminController.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ public function getSitesAction($id)
8282
die($this->_model->getSites($this->getDevice($id), false));
8383
}
8484

85+
/**
86+
* Retrieves a Device by id, or null when not found.
87+
*
88+
* @param int $id The Device Id to look for.
89+
* @return Devices|null The Device when found, otherwise null.
90+
*/
8591
private function getDevice($id)
8692
{
8793
return Devices::findFirst([

app/controllers/JellyfinController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
class JellyfinController extends BaseController
88
{
9+
/**
10+
* Retrieves all Jellyfin libraries.
11+
*/
912
public function viewsAction()
1013
{
1114
die(json_encode(array_flip((new Jellyfin())->getViews())));

app/controllers/PulsewayController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ public function indexAction()
3939
die(json_encode($result));
4040
}
4141

42+
/**
43+
* Retrieves all systems defined in the associated Pulseway account.
44+
*/
4245
public function systemsAction()
4346
{
4447
die(json_encode($this->_model->getSystems()));

app/controllers/SettingsController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use Chell\Models\Users;
1313
use Chell\Models\Devices;
1414
use Chell\Models\MenuItems;
15-
use Chell\Models\MenuItemsUsers;
1615
use Chell\Models\SnmpHosts;
1716
use Chell\Models\SnmpRecords;
1817
use Davidearl\WebAuthn\WebAuthn;
@@ -55,8 +54,8 @@ public function indexAction($activeTab = 'General')
5554
{
5655
$this->view->activeTab = $activeTab;
5756
$this->view->forms = [
58-
'General' => isset($this->generalForm) ? $this->generalForm : new SettingsGeneralForm(),
59-
'Dashboard' => isset($this->dashboardForm) ? $this-> dashboardForm: new SettingsDashboardForm(),
57+
'General' => $this->generalForm ?? new SettingsGeneralForm(),
58+
'Dashboard' => $this->dashboardForm ?? new SettingsDashboardForm(),
6059
];
6160

6261
$logsTotal = 0;
@@ -255,7 +254,7 @@ public function menuAction($id = 0)
255254
}
256255

257256
$item->save();
258-
$item->handlePost(isset($data['user_id']) ? $data['user_id'] : [-1]);
257+
$item->handlePost($data['user_id'] ?? [-1]);
259258

260259
if ($file)
261260
{

app/controllers/SpeedtestController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ public function telemetryAction()
8787
if ($this->request->isPost())
8888
{
8989
$item = new Speedtest($this->request->getPost());
90-
$item->ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
91-
$item->ua = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
92-
$item->lang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
90+
$item->ip = $_SERVER['REMOTE_ADDR'] ?? '';
91+
$item->ua = $_SERVER['HTTP_USER_AGENT'] ?? '';
92+
$item->lang = $_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? '';
9393
$item->extra = $this->whatIsMyBrowser();
9494

9595
die(var_dump($item->save()));

app/forms/SettingsBaseForm.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,23 @@ private function renderElementInternal($element, $hidden = false)
8181
return $html;
8282
}
8383

84+
/**
85+
* Renders the form
86+
*
87+
* @param string $id The HTML id attribute to set on the form.
88+
*/
8489
public function renderForm($id)
8590
{
8691
require APP_PATH . 'app/views/forms/form.phtml';
8792
}
8893

94+
/**
95+
* Summary of renderButton
96+
*
97+
* @param string $button
98+
* @param string $name
99+
* @param mixed $element
100+
*/
89101
public function renderButton($button, $name = '', $element = '')
90102
{
91103
require APP_PATH . 'app/views/forms/buttons/' . $button . '.phtml';

app/forms/SettingsDashboardForm.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ public function isValid($data = null, $entity = null) : bool
3131

3232
if ($valid)
3333
{
34-
$this->config->dashboard->checkDeviceStatesInterval = $data['check-devicestate-interval'];
35-
3634
foreach($this->formFieldClasses as $class)
3735
{
3836
$class->setPostData($this->config, $data);

app/forms/SettingsGeneralForm.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function isValid($data = null, $entity = null) : bool
173173
$this->config->application->debug = isset($data['debug']) && $data['debug']== 'on' ? '1' : '0';
174174
$this->config->application->demoMode = isset($data['demo']) && $data['demo'] == 'on' ? '1' : '0';
175175

176-
foreach($this->formFieldClasses as $class)
176+
foreach ($this->formFieldClasses as $class)
177177
{
178178
$class->setPostData($this->config, $data);
179179
}

app/forms/SettingsMenuItemForm.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,21 @@ public function initialize($entity = null)
5252
'using' => ['id', 'name'],
5353
'useEmpty' => true,
5454
'emptyText' => 'None',
55-
'emptyValue' => 0
55+
'emptyValue' => null
5656
]
5757
);
5858
$device->setLabel('Device');
5959

60+
$allUsers = Users::find();
6061
$users = new Select(
6162
'user_id[]' ,
62-
Users::find(),
63+
$allUsers,
6364
[
6465
'using' => ['id', 'username'],
6566
'multiple' => 'multiple'
6667
],
6768
);
68-
$users->setLabel('Users')->setDefault($this->getSelectedUsers($entity));
69+
$users->setLabel('Users')->setDefault($this->getSelectedUsers($entity, $allUsers));
6970

7071
$this->add($name);
7172
$this->add($url);
@@ -74,7 +75,13 @@ public function initialize($entity = null)
7475
$this->add($users);
7576
}
7677

77-
private function getSelectedUsers($entity)
78+
/**
79+
* Given the MenuItem entity, get the selected users.
80+
*
81+
* @param \Chell\Models\MenuItems $entity The MenuItem to get the selected users for.
82+
* @return array An array of User Ids.
83+
*/
84+
private function getSelectedUsers($entity, $allUsers)
7885
{
7986
$selectedUsers = [];
8087

@@ -87,6 +94,11 @@ private function getSelectedUsers($entity)
8794
}
8895
}
8996

97+
if (!count($selectedUsers) && $allUsers->count() === 1)
98+
{
99+
$selectedUsers = [$allUsers[0]->id];
100+
}
101+
90102
return $selectedUsers;
91103
}
92104
}

app/forms/SettingsSnmpRecordForm.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,7 @@ public function initialize($entity)
3030
$host = new Select(
3131
'snmp_host_id' ,
3232
SnmpHosts::find(),
33-
[
34-
'using' => ['id', 'name'],
35-
'useEmpty' => true,
36-
'emptyText' => 'None',
37-
'emptyValue' => 0
38-
]
33+
['using' => ['id', 'name']]
3934
);
4035
$host->setLabel('Host');
4136

0 commit comments

Comments
 (0)